From d25365c3c13f2fcc4e5574f01106c061c493e63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Hedin=20Br=C3=B8nner?= Date: Sat, 12 Jan 2019 10:31:37 +0100 Subject: [PATCH] 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`. --- .../services/x11/desktop-managers/default.nix | 12 +++---- .../x11/desktop-managers/pantheon.nix | 4 +-- .../services/x11/display-managers/default.nix | 31 +++++++++++++++++++ .../services/x11/display-managers/lightdm.nix | 8 ++--- .../services/x11/display-managers/sddm.nix | 8 ++--- nixos/tests/gnome3-xorg.nix | 2 +- 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/nixos/modules/services/x11/desktop-managers/default.nix b/nixos/modules/services/x11/desktop-managers/default.nix index ed2b09cb21c..7240358c361 100644 --- a/nixos/modules/services/x11/desktop-managers/default.nix +++ b/nixos/modules/services/x11/desktop-managers/default.nix @@ -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; + ''; }; }; diff --git a/nixos/modules/services/x11/desktop-managers/pantheon.nix b/nixos/modules/services/x11/desktop-managers/pantheon.nix index 614f4638cf5..3722bf365ba 100644 --- a/nixos/modules/services/x11/desktop-managers/pantheon.nix +++ b/nixos/modules/services/x11/desktop-managers/pantheon.nix @@ -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 diff --git a/nixos/modules/services/x11/display-managers/default.nix b/nixos/modules/services/x11/display-managers/default.nix index f55bfbfd0c1..1a46e7c02e5 100644 --- a/nixos/modules/services/x11/display-managers/default.nix +++ b/nixos/modules/services/x11/display-managers/default.nix @@ -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 { diff --git a/nixos/modules/services/x11/display-managers/lightdm.nix b/nixos/modules/services/x11/display-managers/lightdm.nix index cf4c05acbcc..71cd6079ea1 100644 --- a/nixos/modules/services/x11/display-managers/lightdm.nix +++ b/nixos/modules/services/x11/display-managers/lightdm.nix @@ -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 diff --git a/nixos/modules/services/x11/display-managers/sddm.nix b/nixos/modules/services/x11/display-managers/sddm.nix index 24e120c4f2c..b51582d2ca5 100644 --- a/nixos/modules/services/x11/display-managers/sddm.nix +++ b/nixos/modules/services/x11/display-managers/sddm.nix @@ -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 diff --git a/nixos/tests/gnome3-xorg.nix b/nixos/tests/gnome3-xorg.nix index eb4c376319b..aa03501f6a5 100644 --- a/nixos/tests/gnome3-xorg.nix +++ b/nixos/tests/gnome3-xorg.nix @@ -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; };