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.
This commit is contained in:
parent
1a0c86ecd0
commit
7d07645cba
@ -1,9 +1,7 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
xcfg = config.services.xserver;
|
xcfg = config.services.xserver;
|
||||||
dmcfg = xcfg.displayManager;
|
dmcfg = xcfg.displayManager;
|
||||||
cfg = dmcfg.sddm;
|
cfg = dmcfg.sddm;
|
||||||
@ -11,87 +9,86 @@ let
|
|||||||
|
|
||||||
sddm = pkgs.libsForQt5.sddm;
|
sddm = pkgs.libsForQt5.sddm;
|
||||||
|
|
||||||
xserverWrapper = pkgs.writeScript "xserver-wrapper" ''
|
iniFmt = pkgs.formats.ini { };
|
||||||
#!/bin/sh
|
|
||||||
|
xserverWrapper = pkgs.writeShellScript "xserver-wrapper" ''
|
||||||
${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
|
${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
|
||||||
exec systemd-cat -t xserver-wrapper ${dmcfg.xserverBin} ${toString dmcfg.xserverArgs} "$@"
|
exec systemd-cat -t xserver-wrapper ${dmcfg.xserverBin} ${toString dmcfg.xserverArgs} "$@"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
Xsetup = pkgs.writeScript "Xsetup" ''
|
Xsetup = pkgs.writeShellScript "Xsetup" ''
|
||||||
#!/bin/sh
|
|
||||||
${cfg.setupScript}
|
${cfg.setupScript}
|
||||||
${dmcfg.setupCommands}
|
${dmcfg.setupCommands}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
Xstop = pkgs.writeScript "Xstop" ''
|
Xstop = pkgs.writeShellScript "Xstop" ''
|
||||||
#!/bin/sh
|
|
||||||
${cfg.stopScript}
|
${cfg.stopScript}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
cfgFile = pkgs.writeText "sddm.conf" ''
|
defaultConfig = {
|
||||||
[General]
|
General = {
|
||||||
HaltCommand=/run/current-system/systemd/bin/systemctl poweroff
|
HaltCommand = "/run/current-system/systemd/bin/systemctl poweroff";
|
||||||
RebootCommand=/run/current-system/systemd/bin/systemctl reboot
|
RebootCommand = "/run/current-system/systemd/bin/systemctl reboot";
|
||||||
${optionalString cfg.autoNumlock ''
|
Numlock = if cfg.autoNumlock then "on" else "none"; # on, off none
|
||||||
Numlock=on
|
};
|
||||||
''}
|
|
||||||
|
|
||||||
[Theme]
|
Theme = {
|
||||||
Current=${cfg.theme}
|
Current = cfg.theme;
|
||||||
ThemeDir=/run/current-system/sw/share/sddm/themes
|
ThemeDir = "/run/current-system/sw/share/sddm/themes";
|
||||||
FacesDir=/run/current-system/sw/share/sddm/faces
|
FacesDir = "/run/current-system/sw/share/sddm/faces";
|
||||||
|
};
|
||||||
|
|
||||||
[Users]
|
Users = {
|
||||||
MaximumUid=${toString config.ids.uids.nixbld}
|
MaximumUid = config.ids.uids.nixbld;
|
||||||
HideUsers=${concatStringsSep "," dmcfg.hiddenUsers}
|
HideUsers = concatStringsSep "," dmcfg.hiddenUsers;
|
||||||
HideShells=/run/current-system/sw/bin/nologin
|
HideShells = "/run/current-system/sw/bin/nologin";
|
||||||
|
};
|
||||||
|
|
||||||
[X11]
|
X11 = {
|
||||||
MinimumVT=${toString (if xcfg.tty != null then xcfg.tty else 7)}
|
MinimumVT = if xcfg.tty != null then xcfg.tty else 7;
|
||||||
ServerPath=${xserverWrapper}
|
ServerPath = toString xserverWrapper;
|
||||||
XephyrPath=${pkgs.xorg.xorgserver.out}/bin/Xephyr
|
XephyrPath = "${pkgs.xorg.xorgserver.out}/bin/Xephyr";
|
||||||
SessionCommand=${dmcfg.sessionData.wrapper}
|
SessionCommand = toString dmcfg.sessionData.wrapper;
|
||||||
SessionDir=${dmcfg.sessionData.desktops}/share/xsessions
|
SessionDir = "${dmcfg.sessionData.desktops}/share/xsessions";
|
||||||
XauthPath=${pkgs.xorg.xauth}/bin/xauth
|
XauthPath = "${pkgs.xorg.xauth}/bin/xauth";
|
||||||
DisplayCommand=${Xsetup}
|
DisplayCommand = toString Xsetup;
|
||||||
DisplayStopCommand=${Xstop}
|
DisplayStopCommand = toString Xstop;
|
||||||
EnableHidpi=${boolToString cfg.enableHidpi}
|
EnableHiDPI = cfg.enableHidpi;
|
||||||
|
};
|
||||||
|
|
||||||
[Wayland]
|
Wayland = {
|
||||||
EnableHidpi=${boolToString cfg.enableHidpi}
|
EnableHiDPI = cfg.enableHidpi;
|
||||||
SessionDir=${dmcfg.sessionData.desktops}/share/wayland-sessions
|
SessionDir = "${dmcfg.sessionData.desktops}/share/wayland-sessions";
|
||||||
|
};
|
||||||
|
} // lib.optionalAttrs dmcfg.autoLogin.enable {
|
||||||
|
Autologin = {
|
||||||
|
User = dmcfg.autoLogin.user;
|
||||||
|
Session = autoLoginSessionName;
|
||||||
|
Relogin = cfg.autoLogin.relogin;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
${optionalString dmcfg.autoLogin.enable ''
|
cfgFile =
|
||||||
[Autologin]
|
iniFmt.generate "sddm.conf" (lib.recursiveUpdate defaultConfig cfg.settings);
|
||||||
User=${dmcfg.autoLogin.user}
|
|
||||||
Session=${autoLoginSessionName}.desktop
|
|
||||||
Relogin=${boolToString cfg.autoLogin.relogin}
|
|
||||||
''}
|
|
||||||
|
|
||||||
${cfg.extraConfig}
|
autoLoginSessionName =
|
||||||
'';
|
"${dmcfg.sessionData.autologinSession}.desktop";
|
||||||
|
|
||||||
autoLoginSessionName = dmcfg.sessionData.autologinSession;
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(mkRemovedOptionModule [ "services" "xserver" "displayManager" "sddm" "themes" ]
|
(mkRemovedOptionModule
|
||||||
|
[ "services" "xserver" "displayManager" "sddm" "themes" ]
|
||||||
"Set the option `services.xserver.displayManager.sddm.package' instead.")
|
"Set the option `services.xserver.displayManager.sddm.package' instead.")
|
||||||
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "enable" ] [
|
(mkRenamedOptionModule
|
||||||
"services"
|
[ "services" "xserver" "displayManager" "sddm" "autoLogin" "enable" ]
|
||||||
"xserver"
|
[ "services" "xserver" "displayManager" "autoLogin" "enable" ])
|
||||||
"displayManager"
|
(mkRenamedOptionModule
|
||||||
"autoLogin"
|
[ "services" "xserver" "displayManager" "sddm" "autoLogin" "user" ]
|
||||||
"enable"
|
[ "services" "xserver" "displayManager" "autoLogin" "user" ])
|
||||||
])
|
(mkRemovedOptionModule
|
||||||
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "user" ] [
|
[ "services" "xserver" "displayManager" "sddm" "extraConfig" ]
|
||||||
"services"
|
"Set the option `services.xserver.displayManager.sddm.settings' instead.")
|
||||||
"xserver"
|
|
||||||
"displayManager"
|
|
||||||
"autoLogin"
|
|
||||||
"user"
|
|
||||||
])
|
|
||||||
];
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
@ -110,22 +107,22 @@ in
|
|||||||
default = true;
|
default = true;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable automatic HiDPI mode.
|
Whether to enable automatic HiDPI mode.
|
||||||
</para>
|
|
||||||
<para>
|
|
||||||
Versions up to 0.17 are broken so this only works from 0.18 onwards.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
settings = mkOption {
|
||||||
type = types.lines;
|
type = iniFmt.type;
|
||||||
default = "";
|
default = { };
|
||||||
example = ''
|
example = ''
|
||||||
[Autologin]
|
{
|
||||||
User=john
|
Autologin = {
|
||||||
Session=plasma.desktop
|
User = "john";
|
||||||
|
Session = "plasma.desktop";
|
||||||
|
};
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
Extra lines appended to the configuration of SDDM.
|
Extra settings merged in and overwritting defaults in sddm.conf.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -168,28 +165,38 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
# Configuration for automatic login specific to SDDM
|
# Configuration for automatic login specific to SDDM
|
||||||
autoLogin.relogin = mkOption {
|
autoLogin = {
|
||||||
type = types.bool;
|
relogin = mkOption {
|
||||||
default = false;
|
type = types.bool;
|
||||||
description = ''
|
default = false;
|
||||||
If true automatic login will kick in again on session exit (logout), otherwise it
|
description = ''
|
||||||
will only log in automatically when the display-manager is started.
|
If true automatic login will kick in again on session exit (logout), otherwise it
|
||||||
'';
|
will only log in automatically when the display-manager is started.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
minimumUid = mkOption {
|
||||||
|
type = types.ints.u16;
|
||||||
|
default = 1000;
|
||||||
|
description = ''
|
||||||
|
Minimum user ID for auto-login user.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = xcfg.enable;
|
{
|
||||||
|
assertion = xcfg.enable;
|
||||||
message = ''
|
message = ''
|
||||||
SDDM requires services.xserver.enable to be true
|
SDDM requires services.xserver.enable to be true
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{ assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
|
{
|
||||||
|
assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
|
||||||
message = ''
|
message = ''
|
||||||
SDDM auto-login requires that services.xserver.displayManager.defaultSession is set.
|
SDDM auto-login requires that services.xserver.displayManager.defaultSession is set.
|
||||||
'';
|
'';
|
||||||
@ -230,7 +237,7 @@ in
|
|||||||
|
|
||||||
sddm-autologin.text = ''
|
sddm-autologin.text = ''
|
||||||
auth requisite pam_nologin.so
|
auth requisite pam_nologin.so
|
||||||
auth required pam_succeed_if.so uid >= 1000 quiet
|
auth required pam_succeed_if.so uid >= ${toString cfg.autoLogin.minimumUid} quiet
|
||||||
auth required pam_permit.so
|
auth required pam_permit.so
|
||||||
|
|
||||||
account include sddm
|
account include sddm
|
||||||
|
Loading…
Reference in New Issue
Block a user