2017-01-07 19:16:26 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xsession;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
xsession = {
|
|
|
|
enable = mkEnableOption "X Session";
|
|
|
|
|
|
|
|
windowManager = mkOption {
|
|
|
|
type = types.str;
|
2017-05-06 12:51:08 +02:00
|
|
|
example = literalExample ''
|
|
|
|
let
|
|
|
|
xmonad = pkgs.xmonad-with-packages.override {
|
|
|
|
packages = self: [ self.xmonad-contrib self.taffybar ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
"''${xmonad}/bin/xmonad";
|
|
|
|
'';
|
2017-01-07 19:16:26 +01:00
|
|
|
description = "Path to window manager to exec.";
|
|
|
|
};
|
|
|
|
|
|
|
|
initExtra = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra shell commands to run during initialization.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.user.services.setxkbmap = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Set up keyboard in X";
|
2017-06-26 18:34:09 +02:00
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Install = {
|
2017-01-09 22:45:42 +01:00
|
|
|
WantedBy = [ "graphical-session.target" ];
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart =
|
|
|
|
let
|
|
|
|
args = concatStringsSep " " (
|
|
|
|
[
|
|
|
|
"-layout '${config.home.keyboard.layout}'"
|
|
|
|
"-variant '${config.home.keyboard.variant}'"
|
|
|
|
] ++
|
|
|
|
(map (v: "-option '${v}'") config.home.keyboard.options)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
"${pkgs.xorg.setxkbmap}/bin/setxkbmap ${args}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-06-26 18:26:54 +02:00
|
|
|
# A basic graphical session target for Home Manager.
|
|
|
|
systemd.user.targets.he-graphical-session = {
|
2017-01-15 10:46:20 +01:00
|
|
|
Unit = {
|
2017-06-26 18:26:54 +02:00
|
|
|
Description = "Home Manager X session";
|
|
|
|
Requires = [ "graphical-session-pre.target" ];
|
|
|
|
BindsTo = [ "graphical-session.target" ];
|
2017-01-09 22:45:42 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
home.file.".xsession" = {
|
|
|
|
mode = "555";
|
|
|
|
text = ''
|
2017-01-28 18:29:27 +01:00
|
|
|
if [[ -e "$HOME/.profile" ]]; then
|
|
|
|
. "$HOME/.profile"
|
|
|
|
fi
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-06-26 18:26:54 +02:00
|
|
|
# If there are any running services from a previous session.
|
|
|
|
systemctl --user stop graphical-session.target graphical-session-pre.target
|
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
|
|
|
|
systemctl --user import-environment DISPLAY
|
|
|
|
systemctl --user import-environment SSH_AUTH_SOCK
|
2017-01-09 22:55:44 +01:00
|
|
|
systemctl --user import-environment XAUTHORITY
|
2017-01-07 19:16:26 +01:00
|
|
|
systemctl --user import-environment XDG_DATA_DIRS
|
|
|
|
systemctl --user import-environment XDG_RUNTIME_DIR
|
2017-01-15 10:46:20 +01:00
|
|
|
|
2017-06-26 18:26:54 +02:00
|
|
|
systemctl --user start he-graphical-session.target
|
2017-01-07 19:16:26 +01:00
|
|
|
|
|
|
|
${cfg.initExtra}
|
|
|
|
|
|
|
|
${cfg.windowManager}
|
|
|
|
|
2017-01-09 22:45:42 +01:00
|
|
|
systemctl --user stop graphical-session.target
|
2017-01-15 10:46:20 +01:00
|
|
|
systemctl --user stop graphical-session-pre.target
|
|
|
|
|
|
|
|
# Wait until the units actually stop.
|
|
|
|
while [[ -n "$(systemctl --user --no-legend --state=deactivating list-units)" ]]; do
|
|
|
|
sleep 0.5
|
|
|
|
done
|
2017-01-07 19:16:26 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|