xsession: remove xsession.windowManager option

This removes the deprecated use of `xsession.windowManager` as a
string.

This commit also adjusts the xmonad module to become a full module.
I.e., the backwards compatibility hack was removed.
This commit is contained in:
Robert Helgesson 2017-10-31 14:05:54 +01:00
parent 82d6aa0c97
commit 78a1424582
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
4 changed files with 120 additions and 187 deletions

View file

@ -57,6 +57,7 @@ let
./services/taffybar.nix ./services/taffybar.nix
./services/tahoe-lafs.nix ./services/tahoe-lafs.nix
./services/udiskie.nix ./services/udiskie.nix
./services/window-managers/xmonad.nix
./services/xscreensaver.nix ./services/xscreensaver.nix
./systemd.nix ./systemd.nix
./xresources.nix ./xresources.nix

View file

@ -240,22 +240,6 @@ in
''; '';
} }
{
time = "2017-09-28T21:39:45+00:00";
condition =
config.xsession.enable
&& config.xsession.windowManager.usesDeprecated;
message = ''
The 'xsession.windowManager' option is now deprecated,
please use 'xsession.windowManager.command' instead.
This change was made to prepare for window manager modules
under the 'xsession.windowManager' namespace. For example,
'xsession.windowManager.xmonad' and
'xsession.windowManager.i3'.
'';
}
{ {
time = "2017-09-30T09:44:18+00:00"; time = "2017-09-30T09:44:18+00:00";
condition = with config.programs.vim; condition = with config.programs.vim;
@ -339,19 +323,6 @@ in
''; '';
} }
{
time = "2017-10-19T09:33:10+00:00";
condition =
config.xsession.enable
&& config.xsession.windowManager.usesDeprecated;
message = ''
The 'xsession.windowManager' option is deprecated and will
be removed on October 31, 2017. To avoid evaluation errors
you must change to using 'xsession.windowManager.command'
before that date.
'';
}
{ {
time = "2017-10-20T12:15:27+00:00"; time = "2017-10-20T12:15:27+00:00";
condition = with config.systemd.user; condition = with config.systemd.user;

View file

@ -1,10 +1,11 @@
{ pkgs }: { config, lib, ... }: { config, lib, pkgs, ... }:
with lib; with lib;
with import ../../lib/dag.nix { inherit lib; };
let let
cfg = config.xmonad; cfg = config.xsession.windowManager.xmonad;
xmonad = pkgs.xmonad-with-packages.override { xmonad = pkgs.xmonad-with-packages.override {
ghcWithPackages = cfg.haskellPackages.ghcWithPackages; ghcWithPackages = cfg.haskellPackages.ghcWithPackages;
@ -19,7 +20,7 @@ in
{ {
options = { options = {
xmonad = { xsession.windowManager.xmonad = {
enable = mkEnableOption "xmonad window manager"; enable = mkEnableOption "xmonad window manager";
haskellPackages = mkOption { haskellPackages = mkOption {
@ -80,7 +81,32 @@ in
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable (mkMerge [
command = "${xmonad}/bin/xmonad"; {
}; xsession.windowManager.command = "${xmonad}/bin/xmonad";
}
(mkIf (cfg.config != null) {
home.file.".xmonad/xmonad.hs".source = cfg.config;
home.activation.checkXmonad = dagEntryBefore [ "linkGeneration" ] ''
if ! cmp --quiet "${cfg.config}" "$HOME/.xmonad/xmonad.hs"; then
xmonadChanged=1
fi
'';
home.activation.applyXmonad = dagEntryAfter [ "linkGeneration" ] ''
if [[ -v xmonadChanged ]]; then
echo "Recompiling xmonad"
${config.xsession.windowManager.command} --recompile
# Attempt to restart xmonad if X is running.
if [[ -v DISPLAY ]] ; then
echo "Restarting xmonad"
${config.xsession.windowManager.command} --restart
fi
fi
'';
})
]);
} }

View file

@ -1,16 +1,21 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib; with lib;
with import ./lib/dag.nix { inherit lib; };
let let
cfg = config.xsession; cfg = config.xsession;
# Hack to support xsession.windowManager.command option. in
wmBaseModule = {
options = { {
command = mkOption { meta.maintainers = [ maintainers.rycee ];
options = {
xsession = {
enable = mkEnableOption "X Session";
windowManager.command = mkOption {
type = types.str; type = types.str;
example = literalExample '' example = literalExample ''
let let
@ -25,39 +30,6 @@ let
''; '';
}; };
usesDeprecated = mkOption {
internal = true;
type = types.bool;
default = false;
};
};
};
xmonadModule = import ./services/window-managers/xmonad.nix {
inherit pkgs;
};
in
{
meta.maintainers = [ maintainers.rycee ];
options = {
xsession = {
enable = mkEnableOption "X Session";
windowManager = mkOption {
type =
types.coercedTo
types.str
(command: { inherit command; usesDeprecated = true; })
(types.submodule [ wmBaseModule xmonadModule ]);
description = ''
Window manager start command. DEPRECATED: Use
<varname>xsession.windowManager.command</varname> instead.
'';
};
profileExtra = mkOption { profileExtra = mkOption {
type = types.lines; type = types.lines;
default = ""; default = "";
@ -72,125 +44,88 @@ in
}; };
}; };
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable {
(mkIf cfg.windowManager.usesDeprecated { systemd.user.services.setxkbmap = {
warnings = [ Unit = {
("xsession.windowManager is deprecated, " Description = "Set up keyboard in X";
+ "please use xsession.windowManager.command") After = [ "graphical-session-pre.target" ];
]; PartOf = [ "graphical-session.target" ];
}) };
# Hack to support xsession.windowManager as a string. Once that is Install = {
# removed this code should go back into the xmonad.nix file. WantedBy = [ "graphical-session.target" ];
(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" ] '' Service = {
if ! cmp --quiet \ Type = "oneshot";
"${cfg.windowManager.xmonad.config}" \ ExecStart =
"$HOME/.xmonad/xmonad.hs"; then let
xmonadChanged=1 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}";
};
};
# 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" ];
};
};
home.file.".xprofile".text = ''
if [[ -e "$HOME/.profile" ]]; then
. "$HOME/.profile"
fi fi
'';
home.activation.applyXmonad = dagEntryAfter [ "linkGeneration" ] '' # If there are any running services from a previous session.
if [[ -v xmonadChanged ]]; then # Need to run this in xprofile because the NixOS xsession
echo "Recompiling xmonad" # script starts up graphical-session.target.
${cfg.windowManager.command} --recompile systemctl --user stop graphical-session.target graphical-session-pre.target
# Attempt to restart xmonad if X is running. systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
if [[ -v DISPLAY ]] ; then systemctl --user import-environment DISPLAY
echo "Restarting xmonad" systemctl --user import-environment SSH_AUTH_SOCK
${cfg.windowManager.command} --restart systemctl --user import-environment XAUTHORITY
fi systemctl --user import-environment XDG_DATA_DIRS
systemctl --user import-environment XDG_RUNTIME_DIR
systemctl --user import-environment XDG_SESSION_ID
${cfg.profileExtra}
export HM_XPROFILE_SOURCED=1
'';
home.file.".xsession" = {
mode = "555";
text = ''
if [[ ! -v HM_XPROFILE_SOURCED ]]; then
. ~/.xprofile
fi fi
unset HM_XPROFILE_SOURCED
systemctl --user start hm-graphical-session.target
${cfg.initExtra}
${cfg.windowManager.command}
systemctl --user stop graphical-session.target
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
''; '';
}) };
};
{
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}";
};
};
# 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" ];
};
};
home.file.".xprofile".text = ''
if [[ -e "$HOME/.profile" ]]; then
. "$HOME/.profile"
fi
# If there are any running services from a previous session.
# Need to run this in xprofile because the NixOS xsession
# script starts up graphical-session.target.
systemctl --user stop graphical-session.target graphical-session-pre.target
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
${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
systemctl --user start hm-graphical-session.target
${cfg.initExtra}
${cfg.windowManager.command}
systemctl --user stop graphical-session.target
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
'';
};
}
]);
} }