git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/sddm: use attrs instead of plain text

Instead of treating the sddm config a wall of text that doesn't allow us to override anything, turn it into an attribute set. We dump `extraConfig` and instead introduce `settings` that is merged with the module defaults to provide the final configuration. There is some additional noise in here due to nixpkgs-fmt.

commit7d07645cba1e087e4543159245907fe8309dfc85 authorPeter Hoeg <peter@hoeg.com> dateSat 26 Dec 2020, 19:26 (6 years ago) parent1a0c86e
1 file changed+95−88
nixos/modules/services/x11/display-managers/sddm.nix+95−88
nixos/modules/services/x11/display-managers/sddm.nix+95−88
@@ -1,9 +1,7 @@
11{ config, lib, pkgs, ... }:
22
33with lib;
4−
54let
6−
75 xcfg = config.services.xserver;
86 dmcfg = xcfg.displayManager;
97 cfg = dmcfg.sddm;
@@ -11,87 +9,86 @@ let
119
1210 sddm = pkgs.libsForQt5.sddm;
1311
14− xserverWrapper = pkgs.writeScript "xserver-wrapper" ''
15− #!/bin/sh
12+ iniFmt = pkgs.formats.ini { };
13+
14+ xserverWrapper = pkgs.writeShellScript "xserver-wrapper" ''
1615 ${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
1716 exec systemd-cat -t xserver-wrapper ${dmcfg.xserverBin} ${toString dmcfg.xserverArgs} "$@"
1817 '';
1918
20− Xsetup = pkgs.writeScript "Xsetup" ''
21− #!/bin/sh
19+ Xsetup = pkgs.writeShellScript "Xsetup" ''
2220 ${cfg.setupScript}
2321 ${dmcfg.setupCommands}
2422 '';
2523
26− Xstop = pkgs.writeScript "Xstop" ''
27− #!/bin/sh
24+ Xstop = pkgs.writeShellScript "Xstop" ''
2825 ${cfg.stopScript}
2926 '';
3027
31− cfgFile = pkgs.writeText "sddm.conf" ''
32− [General]
33− HaltCommand=/run/current-system/systemd/bin/systemctl poweroff
34− RebootCommand=/run/current-system/systemd/bin/systemctl reboot
35− ${optionalString cfg.autoNumlock ''
36− Numlock=on
37− ''}
38−
39− [Theme]
40− Current=${cfg.theme}
41− ThemeDir=/run/current-system/sw/share/sddm/themes
42− FacesDir=/run/current-system/sw/share/sddm/faces
43−
44− [Users]
45− MaximumUid=${toString config.ids.uids.nixbld}
46− HideUsers=${concatStringsSep "," dmcfg.hiddenUsers}
47− HideShells=/run/current-system/sw/bin/nologin
48−
49− [X11]
50− MinimumVT=${toString (if xcfg.tty != null then xcfg.tty else 7)}
51− ServerPath=${xserverWrapper}
52− XephyrPath=${pkgs.xorg.xorgserver.out}/bin/Xephyr
53− SessionCommand=${dmcfg.sessionData.wrapper}
54− SessionDir=${dmcfg.sessionData.desktops}/share/xsessions
55− XauthPath=${pkgs.xorg.xauth}/bin/xauth
56− DisplayCommand=${Xsetup}
57− DisplayStopCommand=${Xstop}
58− EnableHidpi=${boolToString cfg.enableHidpi}
59−
60− [Wayland]
61− EnableHidpi=${boolToString cfg.enableHidpi}
62− SessionDir=${dmcfg.sessionData.desktops}/share/wayland-sessions
63−
64− ${optionalString dmcfg.autoLogin.enable ''
65− [Autologin]
66− User=${dmcfg.autoLogin.user}
67− Session=${autoLoginSessionName}.desktop
68− Relogin=${boolToString cfg.autoLogin.relogin}
69− ''}
70−
71− ${cfg.extraConfig}
72− '';
28+ defaultConfig = {
29+ General = {
30+ HaltCommand = "/run/current-system/systemd/bin/systemctl poweroff";
31+ RebootCommand = "/run/current-system/systemd/bin/systemctl reboot";
32+ Numlock = if cfg.autoNumlock then "on" else "none"; # on, off none
33+ };
34+
35+ Theme = {
36+ Current = cfg.theme;
37+ ThemeDir = "/run/current-system/sw/share/sddm/themes";
38+ FacesDir = "/run/current-system/sw/share/sddm/faces";
39+ };
40+
41+ Users = {
42+ MaximumUid = config.ids.uids.nixbld;
43+ HideUsers = concatStringsSep "," dmcfg.hiddenUsers;
44+ HideShells = "/run/current-system/sw/bin/nologin";
45+ };
7346
74− autoLoginSessionName = dmcfg.sessionData.autologinSession;
47+ X11 = {
48+ MinimumVT = if xcfg.tty != null then xcfg.tty else 7;
49+ ServerPath = toString xserverWrapper;
50+ XephyrPath = "${pkgs.xorg.xorgserver.out}/bin/Xephyr";
51+ SessionCommand = toString dmcfg.sessionData.wrapper;
52+ SessionDir = "${dmcfg.sessionData.desktops}/share/xsessions";
53+ XauthPath = "${pkgs.xorg.xauth}/bin/xauth";
54+ DisplayCommand = toString Xsetup;
55+ DisplayStopCommand = toString Xstop;
56+ EnableHiDPI = cfg.enableHidpi;
57+ };
58+
59+ Wayland = {
60+ EnableHiDPI = cfg.enableHidpi;
61+ SessionDir = "${dmcfg.sessionData.desktops}/share/wayland-sessions";
62+ };
63+ } // lib.optionalAttrs dmcfg.autoLogin.enable {
64+ Autologin = {
65+ User = dmcfg.autoLogin.user;
66+ Session = autoLoginSessionName;
67+ Relogin = cfg.autoLogin.relogin;
68+ };
69+ };
70+
71+ cfgFile =
72+ iniFmt.generate "sddm.conf" (lib.recursiveUpdate defaultConfig cfg.settings);
73+
74+ autoLoginSessionName =
75+ "${dmcfg.sessionData.autologinSession}.desktop";
7576
7677in
7778{
7879 imports = [
79− (mkRemovedOptionModule [ "services" "xserver" "displayManager" "sddm" "themes" ]
80+ (mkRemovedOptionModule
81+ [ "services" "xserver" "displayManager" "sddm" "themes" ]
8082 "Set the option `services.xserver.displayManager.sddm.package' instead.")
81− (mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "enable" ] [
82− "services"
83− "xserver"
84− "displayManager"
85− "autoLogin"
86− "enable"
87− ])
88− (mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "user" ] [
89− "services"
90− "xserver"
91− "displayManager"
92− "autoLogin"
93− "user"
94− ])
83+ (mkRenamedOptionModule
84+ [ "services" "xserver" "displayManager" "sddm" "autoLogin" "enable" ]
85+ [ "services" "xserver" "displayManager" "autoLogin" "enable" ])
86+ (mkRenamedOptionModule
87+ [ "services" "xserver" "displayManager" "sddm" "autoLogin" "user" ]
88+ [ "services" "xserver" "displayManager" "autoLogin" "user" ])
89+ (mkRemovedOptionModule
90+ [ "services" "xserver" "displayManager" "sddm" "extraConfig" ]
91+ "Set the option `services.xserver.displayManager.sddm.settings' instead.")
9592 ];
9693
9794 options = {
@@ -110,22 +107,22 @@ in
110107 default = true;
111108 description = ''
112109 Whether to enable automatic HiDPI mode.
113− </para>
114− <para>
115− Versions up to 0.17 are broken so this only works from 0.18 onwards.
116110 '';
117111 };
118112
119− extraConfig = mkOption {
120− type = types.lines;
121− default = "";
113+ settings = mkOption {
114+ type = iniFmt.type;
115+ default = { };
122116 example = ''
123− [Autologin]
124− User=john
125− Session=plasma.desktop
117+ {
118+ Autologin = {
119+ User = "john";
120+ Session = "plasma.desktop";
121+ };
122+ }
126123 '';
127124 description = ''
128− Extra lines appended to the configuration of SDDM.
125+ Extra settings merged in and overwritting defaults in sddm.conf.
129126 '';
130127 };
131128
@@ -168,28 +165,38 @@ in
168165 };
169166
170167 # Configuration for automatic login specific to SDDM
171− autoLogin.relogin = mkOption {
172− type = types.bool;
173− default = false;
174− description = ''
175− If true automatic login will kick in again on session exit (logout), otherwise it
176− will only log in automatically when the display-manager is started.
177− '';
168+ autoLogin = {
169+ relogin = mkOption {
170+ type = types.bool;
171+ default = false;
172+ description = ''
173+ If true automatic login will kick in again on session exit (logout), otherwise it
174+ will only log in automatically when the display-manager is started.
175+ '';
176+ };
177+
178+ minimumUid = mkOption {
179+ type = types.ints.u16;
180+ default = 1000;
181+ description = ''
182+ Minimum user ID for auto-login user.
183+ '';
184+ };
178185 };
179−
180186 };
181−
182187 };
183188
184189 config = mkIf cfg.enable {
185190
186191 assertions = [
187− { assertion = xcfg.enable;
192+ {
193+ assertion = xcfg.enable;
188194 message = ''
189195 SDDM requires services.xserver.enable to be true
190196 '';
191197 }
192− { assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
198+ {
199+ assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
193200 message = ''
194201 SDDM auto-login requires that services.xserver.displayManager.defaultSession is set.
195202 '';
@@ -230,7 +237,7 @@ in
230237
231238 sddm-autologin.text = ''
232239 auth requisite pam_nologin.so
233− auth required pam_succeed_if.so uid >= 1000 quiet
240+ auth required pam_succeed_if.so uid >= ${toString cfg.autoLogin.minimumUid} quiet
234241 auth required pam_permit.so
235242
236243 account include sddm