2017-01-07 18:16:26 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xsession;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
xsession = {
|
|
|
|
enable = mkEnableOption "X Session";
|
|
|
|
|
|
|
|
windowManager = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.str;
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
|
|
|
Install = {
|
2017-01-09 21:45:42 +00:00
|
|
|
WantedBy = [ "graphical-session.target" ];
|
2017-01-07 18:16:26 +00: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-01-15 09:46:20 +00:00
|
|
|
# For stuff that needs to start just before a graphical session
|
|
|
|
# starts.
|
|
|
|
systemd.user.targets.graphical-session-pre = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Pre-graphical session";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-09 21:45:42 +00:00
|
|
|
# A basic graphical session target. Apparently this will come
|
|
|
|
# standard in future Systemd versions.
|
|
|
|
systemd.user.targets.graphical-session = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Graphical session";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
home.file.".xsession" = {
|
|
|
|
mode = "555";
|
|
|
|
text = ''
|
2017-01-28 17:29:27 +00:00
|
|
|
if [[ -e "$HOME/.profile" ]]; then
|
|
|
|
. "$HOME/.profile"
|
|
|
|
fi
|
2017-01-07 18:16:26 +00:00
|
|
|
|
|
|
|
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
|
|
|
|
systemctl --user import-environment DISPLAY
|
|
|
|
systemctl --user import-environment SSH_AUTH_SOCK
|
2017-01-09 21:55:44 +00:00
|
|
|
systemctl --user import-environment XAUTHORITY
|
2017-01-07 18:16:26 +00:00
|
|
|
systemctl --user import-environment XDG_DATA_DIRS
|
|
|
|
systemctl --user import-environment XDG_RUNTIME_DIR
|
2017-01-15 09:46:20 +00:00
|
|
|
|
|
|
|
systemctl --user restart graphical-session-pre.target
|
|
|
|
systemctl --user restart graphical-session.target
|
2017-01-07 18:16:26 +00:00
|
|
|
|
|
|
|
${cfg.initExtra}
|
|
|
|
|
|
|
|
${cfg.windowManager}
|
|
|
|
|
2017-01-09 21:45:42 +00:00
|
|
|
systemctl --user stop graphical-session.target
|
2017-01-15 09:46:20 +00: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 18:16:26 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|