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, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
xcfg = config.services.xserver;
|
||||
dmcfg = xcfg.displayManager;
|
||||
cfg = dmcfg.sddm;
|
||||
@ -11,87 +9,86 @@ let
|
||||
|
||||
sddm = pkgs.libsForQt5.sddm;
|
||||
|
||||
xserverWrapper = pkgs.writeScript "xserver-wrapper" ''
|
||||
#!/bin/sh
|
||||
iniFmt = pkgs.formats.ini { };
|
||||
|
||||
xserverWrapper = pkgs.writeShellScript "xserver-wrapper" ''
|
||||
${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
|
||||
exec systemd-cat -t xserver-wrapper ${dmcfg.xserverBin} ${toString dmcfg.xserverArgs} "$@"
|
||||
'';
|
||||
|
||||
Xsetup = pkgs.writeScript "Xsetup" ''
|
||||
#!/bin/sh
|
||||
Xsetup = pkgs.writeShellScript "Xsetup" ''
|
||||
${cfg.setupScript}
|
||||
${dmcfg.setupCommands}
|
||||
'';
|
||||
|
||||
Xstop = pkgs.writeScript "Xstop" ''
|
||||
#!/bin/sh
|
||||
Xstop = pkgs.writeShellScript "Xstop" ''
|
||||
${cfg.stopScript}
|
||||
'';
|
||||
|
||||
cfgFile = pkgs.writeText "sddm.conf" ''
|
||||
[General]
|
||||
HaltCommand=/run/current-system/systemd/bin/systemctl poweroff
|
||||
RebootCommand=/run/current-system/systemd/bin/systemctl reboot
|
||||
${optionalString cfg.autoNumlock ''
|
||||
Numlock=on
|
||||
''}
|
||||
defaultConfig = {
|
||||
General = {
|
||||
HaltCommand = "/run/current-system/systemd/bin/systemctl poweroff";
|
||||
RebootCommand = "/run/current-system/systemd/bin/systemctl reboot";
|
||||
Numlock = if cfg.autoNumlock then "on" else "none"; # on, off none
|
||||
};
|
||||
|
||||
[Theme]
|
||||
Current=${cfg.theme}
|
||||
ThemeDir=/run/current-system/sw/share/sddm/themes
|
||||
FacesDir=/run/current-system/sw/share/sddm/faces
|
||||
Theme = {
|
||||
Current = cfg.theme;
|
||||
ThemeDir = "/run/current-system/sw/share/sddm/themes";
|
||||
FacesDir = "/run/current-system/sw/share/sddm/faces";
|
||||
};
|
||||
|
||||
[Users]
|
||||
MaximumUid=${toString config.ids.uids.nixbld}
|
||||
HideUsers=${concatStringsSep "," dmcfg.hiddenUsers}
|
||||
HideShells=/run/current-system/sw/bin/nologin
|
||||
Users = {
|
||||
MaximumUid = config.ids.uids.nixbld;
|
||||
HideUsers = concatStringsSep "," dmcfg.hiddenUsers;
|
||||
HideShells = "/run/current-system/sw/bin/nologin";
|
||||
};
|
||||
|
||||
[X11]
|
||||
MinimumVT=${toString (if xcfg.tty != null then xcfg.tty else 7)}
|
||||
ServerPath=${xserverWrapper}
|
||||
XephyrPath=${pkgs.xorg.xorgserver.out}/bin/Xephyr
|
||||
SessionCommand=${dmcfg.sessionData.wrapper}
|
||||
SessionDir=${dmcfg.sessionData.desktops}/share/xsessions
|
||||
XauthPath=${pkgs.xorg.xauth}/bin/xauth
|
||||
DisplayCommand=${Xsetup}
|
||||
DisplayStopCommand=${Xstop}
|
||||
EnableHidpi=${boolToString cfg.enableHidpi}
|
||||
X11 = {
|
||||
MinimumVT = if xcfg.tty != null then xcfg.tty else 7;
|
||||
ServerPath = toString xserverWrapper;
|
||||
XephyrPath = "${pkgs.xorg.xorgserver.out}/bin/Xephyr";
|
||||
SessionCommand = toString dmcfg.sessionData.wrapper;
|
||||
SessionDir = "${dmcfg.sessionData.desktops}/share/xsessions";
|
||||
XauthPath = "${pkgs.xorg.xauth}/bin/xauth";
|
||||
DisplayCommand = toString Xsetup;
|
||||
DisplayStopCommand = toString Xstop;
|
||||
EnableHiDPI = cfg.enableHidpi;
|
||||
};
|
||||
|
||||
[Wayland]
|
||||
EnableHidpi=${boolToString cfg.enableHidpi}
|
||||
SessionDir=${dmcfg.sessionData.desktops}/share/wayland-sessions
|
||||
Wayland = {
|
||||
EnableHiDPI = cfg.enableHidpi;
|
||||
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 ''
|
||||
[Autologin]
|
||||
User=${dmcfg.autoLogin.user}
|
||||
Session=${autoLoginSessionName}.desktop
|
||||
Relogin=${boolToString cfg.autoLogin.relogin}
|
||||
''}
|
||||
cfgFile =
|
||||
iniFmt.generate "sddm.conf" (lib.recursiveUpdate defaultConfig cfg.settings);
|
||||
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
|
||||
autoLoginSessionName = dmcfg.sessionData.autologinSession;
|
||||
autoLoginSessionName =
|
||||
"${dmcfg.sessionData.autologinSession}.desktop";
|
||||
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(mkRemovedOptionModule [ "services" "xserver" "displayManager" "sddm" "themes" ]
|
||||
(mkRemovedOptionModule
|
||||
[ "services" "xserver" "displayManager" "sddm" "themes" ]
|
||||
"Set the option `services.xserver.displayManager.sddm.package' instead.")
|
||||
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "enable" ] [
|
||||
"services"
|
||||
"xserver"
|
||||
"displayManager"
|
||||
"autoLogin"
|
||||
"enable"
|
||||
])
|
||||
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "user" ] [
|
||||
"services"
|
||||
"xserver"
|
||||
"displayManager"
|
||||
"autoLogin"
|
||||
"user"
|
||||
])
|
||||
(mkRenamedOptionModule
|
||||
[ "services" "xserver" "displayManager" "sddm" "autoLogin" "enable" ]
|
||||
[ "services" "xserver" "displayManager" "autoLogin" "enable" ])
|
||||
(mkRenamedOptionModule
|
||||
[ "services" "xserver" "displayManager" "sddm" "autoLogin" "user" ]
|
||||
[ "services" "xserver" "displayManager" "autoLogin" "user" ])
|
||||
(mkRemovedOptionModule
|
||||
[ "services" "xserver" "displayManager" "sddm" "extraConfig" ]
|
||||
"Set the option `services.xserver.displayManager.sddm.settings' instead.")
|
||||
];
|
||||
|
||||
options = {
|
||||
@ -110,22 +107,22 @@ in
|
||||
default = true;
|
||||
description = ''
|
||||
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 {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
settings = mkOption {
|
||||
type = iniFmt.type;
|
||||
default = { };
|
||||
example = ''
|
||||
[Autologin]
|
||||
User=john
|
||||
Session=plasma.desktop
|
||||
{
|
||||
Autologin = {
|
||||
User = "john";
|
||||
Session = "plasma.desktop";
|
||||
};
|
||||
}
|
||||
'';
|
||||
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
|
||||
autoLogin.relogin = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
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.
|
||||
'';
|
||||
autoLogin = {
|
||||
relogin = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
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 {
|
||||
|
||||
assertions = [
|
||||
{ assertion = xcfg.enable;
|
||||
{
|
||||
assertion = xcfg.enable;
|
||||
message = ''
|
||||
SDDM requires services.xserver.enable to be true
|
||||
'';
|
||||
}
|
||||
{ assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
|
||||
{
|
||||
assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
|
||||
message = ''
|
||||
SDDM auto-login requires that services.xserver.displayManager.defaultSession is set.
|
||||
'';
|
||||
@ -230,7 +237,7 @@ in
|
||||
|
||||
sddm-autologin.text = ''
|
||||
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
|
||||
|
||||
account include sddm
|
||||
|
Loading…
Reference in New Issue
Block a user