2017-01-07 19:16:26 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2017-09-29 00:15:57 +02:00
|
|
|
with import ./lib/dag.nix { inherit lib; };
|
2017-01-07 19:16:26 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xsession;
|
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
# Hack to support xsession.windowManager.command option.
|
|
|
|
wmBaseModule = {
|
|
|
|
options = {
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = literalExample ''
|
|
|
|
let
|
|
|
|
xmonad = pkgs.xmonad-with-packages.override {
|
|
|
|
packages = self: [ self.xmonad-contrib self.taffybar ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
"''${xmonad}/bin/xmonad";
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Window manager start command.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
usesDeprecated = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-09-29 00:15:57 +02:00
|
|
|
xmonadModule = import ./services/window-managers/xmonad.nix {
|
|
|
|
inherit pkgs;
|
|
|
|
};
|
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2017-09-26 23:40:31 +02:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
options = {
|
|
|
|
xsession = {
|
|
|
|
enable = mkEnableOption "X Session";
|
|
|
|
|
|
|
|
windowManager = mkOption {
|
2017-09-23 00:34:25 +02:00
|
|
|
type =
|
|
|
|
types.coercedTo
|
|
|
|
types.str
|
|
|
|
(command: { inherit command; usesDeprecated = true; })
|
2017-09-29 00:15:57 +02:00
|
|
|
(types.submodule [ wmBaseModule xmonadModule ]);
|
2017-09-23 00:34:25 +02:00
|
|
|
description = ''
|
|
|
|
Window manager start command. DEPRECATED: Use
|
|
|
|
<varname>xsession.windowManager.command</varname> instead.
|
2017-05-06 12:51:08 +02:00
|
|
|
'';
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
|
2017-10-21 14:37:30 +02:00
|
|
|
profileExtra = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra shell commands to run before session start.";
|
|
|
|
};
|
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
initExtra = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra shell commands to run during initialization.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.windowManager.usesDeprecated {
|
|
|
|
warnings = [
|
|
|
|
("xsession.windowManager is deprecated, "
|
|
|
|
+ "please use xsession.windowManager.command")
|
|
|
|
];
|
|
|
|
})
|
|
|
|
|
2017-09-29 00:15:57 +02:00
|
|
|
# Hack to support xsession.windowManager as a string. Once that is
|
|
|
|
# removed this code should go back into the xmonad.nix file.
|
|
|
|
(mkIf (cfg.windowManager.xmonad.enable
|
|
|
|
&& cfg.windowManager.xmonad.config != null) {
|
|
|
|
home.file.".xmonad/xmonad.hs".source = cfg.windowManager.xmonad.config;
|
|
|
|
|
|
|
|
home.activation.checkXmonad = dagEntryBefore [ "linkGeneration" ] ''
|
|
|
|
if ! cmp --quiet \
|
|
|
|
"${cfg.windowManager.xmonad.config}" \
|
|
|
|
"$HOME/.xmonad/xmonad.hs"; then
|
|
|
|
xmonadChanged=1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
home.activation.applyXmonad = dagEntryAfter [ "linkGeneration" ] ''
|
|
|
|
if [[ -v xmonadChanged ]]; then
|
|
|
|
echo "Recompiling xmonad"
|
|
|
|
${cfg.windowManager.command} --recompile
|
|
|
|
|
|
|
|
# Attempt to restart xmonad if X is running.
|
|
|
|
if [[ -v DISPLAY ]] ; then
|
|
|
|
echo "Restarting xmonad"
|
|
|
|
${cfg.windowManager.command} --restart
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
{
|
|
|
|
systemd.user.services.setxkbmap = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Set up keyboard in X";
|
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Install = {
|
|
|
|
WantedBy = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
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-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
# A basic graphical session target for Home Manager.
|
|
|
|
systemd.user.targets.hm-graphical-session = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Home Manager X session";
|
|
|
|
Requires = [ "graphical-session-pre.target" ];
|
|
|
|
BindsTo = [ "graphical-session.target" ];
|
|
|
|
};
|
2017-01-09 22:45:42 +01:00
|
|
|
};
|
|
|
|
|
2017-10-21 14:37:30 +02:00
|
|
|
home.file.".xprofile".text = ''
|
2017-09-23 00:34:25 +02:00
|
|
|
if [[ -e "$HOME/.profile" ]]; then
|
|
|
|
. "$HOME/.profile"
|
|
|
|
fi
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
# If there are any running services from a previous session.
|
2017-10-21 14:37:30 +02:00
|
|
|
# Need to run this in xprofile because the NixOS xsession
|
|
|
|
# script starts up graphical-session.target.
|
2017-09-23 00:34:25 +02:00
|
|
|
systemctl --user stop graphical-session.target graphical-session-pre.target
|
2017-06-26 18:26:54 +02:00
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
|
|
|
|
systemctl --user import-environment DISPLAY
|
|
|
|
systemctl --user import-environment SSH_AUTH_SOCK
|
|
|
|
systemctl --user import-environment XAUTHORITY
|
|
|
|
systemctl --user import-environment XDG_DATA_DIRS
|
|
|
|
systemctl --user import-environment XDG_RUNTIME_DIR
|
|
|
|
systemctl --user import-environment XDG_SESSION_ID
|
2017-01-15 10:46:20 +01:00
|
|
|
|
2017-10-21 14:37:30 +02:00
|
|
|
${cfg.profileExtra}
|
|
|
|
|
|
|
|
export HM_XPROFILE_SOURCED=1
|
|
|
|
'';
|
|
|
|
|
|
|
|
home.file.".xsession" = {
|
|
|
|
mode = "555";
|
|
|
|
text = ''
|
|
|
|
if [[ ! -v HM_XPROFILE_SOURCED ]]; then
|
|
|
|
. ~/.xprofile
|
|
|
|
fi
|
|
|
|
unset HM_XPROFILE_SOURCED
|
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
systemctl --user start hm-graphical-session.target
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
${cfg.initExtra}
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
${cfg.windowManager.command}
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
systemctl --user stop graphical-session.target
|
|
|
|
systemctl --user stop graphical-session-pre.target
|
2017-01-15 10:46:20 +01:00
|
|
|
|
2017-09-23 00:34:25 +02:00
|
|
|
# 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
|
|
|
}
|