@@ -0,0 +1,108 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+
7+ xcfg = config.services.xserver;
8+ dmcfg = xcfg.displayManager;
9+ cfg = dmcfg.sddm;
10+ xEnv = config.systemd.services."display-manager".environment;
11+
12+ xserverWrapper = pkgs.writeScript "xserver-wrapper" ''
13+ #!/bin/sh
14+ ${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
15+ exec ${dmcfg.xserverBin} ${dmcfg.xserverArgs} "$@"
16+ '';
17+
18+ cfgFile = pkgs.writeText "sddm.conf" ''
19+ [General]
20+ HaltCommand=${pkgs.systemd}/bin/systemctl poweroff
21+ RebootCommand=${pkgs.systemd}/bin/systemctl reboot
22+
23+ [Theme]
24+ Current=${cfg.theme}
25+
26+ [Users]
27+ MaximumUid=${toString config.ids.uids.nixbld}
28+
29+ [XDisplay]
30+ MinimumVT=${toString xcfg.tty}
31+ ServerPath=${xserverWrapper}
32+ XephyrPath=${pkgs.xorg.xorgserver}/bin/Xephyr
33+ SessionCommand=${dmcfg.session.script}
34+ SessionDir=${dmcfg.session.desktops}
35+ XauthPath=${pkgs.xorg.xauth}/bin/xauth
36+ '';
37+
38+in
39+{
40+ options = {
41+
42+ services.xserver.displayManager.sddm = {
43+ enable = mkOption {
44+ type = types.bool;
45+ default = false;
46+ description = ''
47+ Whether to enable sddm as the display manager.
48+ '';
49+ };
50+
51+ theme = mkOption {
52+ type = types.str;
53+ default = "maui";
54+ description = ''
55+ Greeter theme to use.
56+ '';
57+ };
58+ };
59+
60+ };
61+
62+ config = mkIf cfg.enable {
63+
64+ services.xserver.displayManager.slim.enable = false;
65+
66+ services.xserver.displayManager.job = {
67+ logsXsession = true;
68+
69+ #execCmd = "${pkgs.sddm}/bin/sddm";
70+ execCmd = "exec ${pkgs.sddm}/bin/sddm";
71+ };
72+
73+ security.pam.services = {
74+ sddm = {
75+ allowNullPassword = true;
76+ startSession = true;
77+ };
78+
79+ sddm-greeter.text = ''
80+ auth required pam_succeed_if.so audit quiet_success user = sddm
81+ auth optional pam_permit.so
82+
83+ account required pam_succeed_if.so audit quiet_success user = sddm
84+ account sufficient pam_unix.so
85+
86+ password required pam_deny.so
87+
88+ session required pam_succeed_if.so audit quiet_success user = sddm
89+ session required pam_env.so envfile=${config.system.build.pamEnvironment}
90+ session optional ${pkgs.systemd}/lib/security/pam_systemd.so
91+ session optional pam_keyinit.so force revoke
92+ session optional pam_permit.so
93+ '';
94+ };
95+
96+ users.extraUsers.sddm = {
97+ createHome = true;
98+ home = "/var/lib/sddm";
99+ group = "sddm";
100+ uid = config.ids.uids.sddm;
101+ };
102+
103+ environment.etc."sddm.conf".source = cfgFile;
104+
105+ users.extraGroups.sddm.gid = config.ids.gids.sddm;
106+
107+ };
108+}