nixos/displayManager: introduce defaultSession

There's two ways of providing graphical sessions now:
- `displayManager.session` via. `desktopManager.session` and
  `windowManager.session`
- `displayManager.sessionPackages`

`sessionPackages` doesn't make a distinction between desktop and window
managers. This makes selecting a session provided by a package using
`desktopManager.default` nonsensical.

We therefor introduce `displayManager.defaultSession` which can select a session
from either `displayManager.session` or `displayManager.sessionPackages`.

It will default to `desktopManager.default + windowManager.default` as before.
If the dm default is "none" it will select the first provided session from
`sessionPackages`.
This commit is contained in:
Tor Hedin Brønner 2019-01-12 10:31:37 +01:00 committed by Jan Tojnar
parent 58e5290fce
commit d25365c3c1
No known key found for this signature in database
GPG key ID: 7FAB2A15F7A607A4
6 changed files with 44 additions and 21 deletions

View file

@ -96,13 +96,13 @@ in
else if any (w: w.name == defaultDM) cfg.session.list then
defaultDM
else
builtins.trace ''
Default desktop manager (${defaultDM}) not found at evaluation time.
These are the known valid session names:
throw ''
Default desktop manager (${defaultDM}) not found.
Probably you want to change
services.xserver.desktopManager.default = "${defaultDM}";
to one of
${concatMapStringsSep "\n " (w: "services.xserver.desktopManager.default = \"${w.name}\";") cfg.session.list}
It's also possible the default can be found in one of these packages:
${concatMapStringsSep "\n " (p: p.name) config.services.xserver.displayManager.sessionPackages}
'' defaultDM;
'';
};
};

View file

@ -81,9 +81,7 @@ in
services.xserver.displayManager.lightdm.greeters.pantheon.enable = mkDefault true;
# If not set manually Pantheon session cannot be started
# Known issue of https://github.com/NixOS/nixpkgs/pull/43992
services.xserver.desktopManager.default = mkForce "pantheon";
services.xserver.displayManager.defaultSession = "pantheon";
services.xserver.displayManager.sessionCommands = ''
if test "$XDG_CURRENT_DESKTOP" = "Pantheon"; then

View file

@ -327,6 +327,37 @@ in
};
};
defaultSession = mkOption {
type = with types; str // {
description = "session name";
check = d: let
sessionNames = cfg.displayManager.session.names ++
(concatMap (p: p.providedSessions) cfg.displayManager.sessionPackages);
in
assertMsg (str.check d && (d == "none" || (elem d sessionNames))) ''
Default graphical session, '${d}', not found.
Valid names for 'services.xserver.displayManager.defaultSession' are:
${concatStringsSep "\n " sessionNames}
'';
};
default = let
dmDefault = cfg.desktopManager.default;
wmDefault = cfg.windowManager.default;
defaultPackage =
if cfg.displayManager.sessionPackages != [] then
(head (head cfg.displayManager.sessionPackages).providedSessions)
else
null;
defaultDmWm = dmDefault + optionalString (wmDefault != "none") ("+" + wmDefault);
in
if defaultDmWm == "none" && isString defaultPackage then
defaultPackage
else
defaultDmWm;
example = "gnome";
description = "Default graphical session (only effective for LightDM and SDDM).";
};
job = {
preStart = mkOption {

View file

@ -9,9 +9,8 @@ let
xEnv = config.systemd.services.display-manager.environment;
cfg = dmcfg.lightdm;
dmDefault = xcfg.desktopManager.default;
wmDefault = xcfg.windowManager.default;
hasDefaultUserSession = dmDefault != "none" || wmDefault != "none";
defaultSessionName = dmcfg.defaultSession;
hasDefaultUserSession = defaultSessionName != "none";
inherit (pkgs) lightdm writeScript writeText;
@ -71,7 +70,6 @@ let
${cfg.extraSeatDefaults}
'';
defaultSessionName = dmDefault + optionalString (wmDefault != "none") ("+" + wmDefault);
in
{
# Note: the order in which lightdm greeter modules are imported
@ -199,7 +197,7 @@ in
LightDM auto-login requires services.xserver.displayManager.lightdm.autoLogin.user to be set
'';
}
{ assertion = cfg.autoLogin.enable -> dmDefault != "none" || wmDefault != "none";
{ assertion = cfg.autoLogin.enable -> hasDefaultUserSession;
message = ''
LightDM auto-login requires that services.xserver.desktopManager.default and
services.xserver.windowManager.default are set to valid values. The current

View file

@ -71,11 +71,7 @@ let
${cfg.extraConfig}
'';
defaultSessionName =
let
dm = xcfg.desktopManager.default;
wm = xcfg.windowManager.default;
in dm + optionalString (wm != "none") ("+" + wm);
defaultSessionName = dmcfg.defaultSession;
in
{
@ -210,7 +206,7 @@ in
SDDM auto-login requires services.xserver.displayManager.sddm.autoLogin.user to be set
'';
}
{ assertion = cfg.autoLogin.enable -> elem defaultSessionName dmcfg.session.names;
{ assertion = cfg.autoLogin.enable -> defaultSessionName != "none";
message = ''
SDDM auto-login requires that services.xserver.desktopManager.default and
services.xserver.windowManager.default are set to valid values. The current

View file

@ -16,7 +16,7 @@ import ./make-test.nix ({ pkgs, ...} : {
services.xserver.displayManager.lightdm.autoLogin.enable = true;
services.xserver.displayManager.lightdm.autoLogin.user = "alice";
services.xserver.desktopManager.gnome3.enable = true;
services.xserver.desktopManager.default = "gnome-xorg";
services.xserver.displayManager.defaultSession = "gnome-xorg";
virtualisation.memorySize = 1024;
};