1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 dmcfg = config.services.xserver.displayManager;
8
9 cfg = dmcfg.slim;
10
11 slimConfig = pkgs.writeText "slim.cfg"
12 ''
13 xauth_path ${dmcfg.xauthBin}
14 default_xserver ${dmcfg.xserverBin}
15 xserver_arguments ${dmcfg.xserverArgs}
16 sessiondir ${dmcfg.session.desktops}
17 login_cmd exec ${pkgs.stdenv.shell} ${dmcfg.session.script} "%session"
18 halt_cmd ${config.systemd.package}/sbin/shutdown -h now
19 reboot_cmd ${config.systemd.package}/sbin/shutdown -r now
20 ${optionalString (cfg.defaultUser != null) ("default_user " + cfg.defaultUser)}
21 ${optionalString cfg.autoLogin "auto_login yes"}
22 ${cfg.extraConfig}
23 '';
24
25 # Unpack the SLiM theme, or use the default.
26 slimThemesDir =
27 let
28 unpackedTheme = pkgs.stdenv.mkDerivation {
29 name = "slim-theme";
30 buildCommand = ''
31 mkdir -p $out
32 cd $out
33 unpackFile ${cfg.theme}
34 ln -s * default
35 '';
36 };
37 in if cfg.theme == null then "${pkgs.slim}/share/slim/themes" else unpackedTheme;
38
39in
40
41{
42
43 ###### interface
44
45 options = {
46
47 services.xserver.displayManager.slim = {
48
49 enable = mkOption {
50 type = types.bool;
51 default = config.services.xserver.enable;
52 description = ''
53 Whether to enable SLiM as the display manager.
54 '';
55 };
56
57 theme = mkOption {
58 type = types.nullOr types.path;
59 default = pkgs.fetchurl {
60 url = https://github.com/jagajaga/nixos-slim-theme/archive/1.1.tar.gz;
61 sha256 = "66c3020a6716130a20c3898567339b990fbd7888a3b7bbcb688f6544d1c05c31";
62 };
63 example = literalExample ''
64 pkgs.fetchurl {
65 url = "mirror://sourceforge/slim.berlios/slim-wave.tar.gz";
66 sha256 = "0ndr419i5myzcylvxb89m9grl2xyq6fbnyc3lkd711mzlmnnfxdy";
67 }
68 '';
69 description = ''
70 The theme for the SLiM login manager. If not specified, SLiM's
71 default theme is used. See <link
72 xlink:href='http://slim.berlios.de/themes01.php'/> for a
73 collection of themes. TODO: berlios shut down.
74 '';
75 };
76
77 defaultUser = mkOption {
78 type = types.nullOr types.str;
79 default = null;
80 example = "login";
81 description = ''
82 The default user to load. If you put a username here you
83 get it automatically loaded into the username field, and
84 the focus is placed on the password.
85 '';
86 };
87
88 autoLogin = mkOption {
89 type = types.bool;
90 default = false;
91 description = ''
92 Automatically log in as the default user.
93 '';
94 };
95
96 extraConfig = mkOption {
97 type = types.lines;
98 default = "";
99 description = ''
100 Extra configuration options for SLiM login manager. Do not
101 add options that can be configured directly.
102 '';
103 };
104
105 };
106
107 };
108
109
110 ###### implementation
111
112 config = mkIf cfg.enable {
113
114 services.xserver.displayManager.job =
115 { preStart =
116 ''
117 rm -f /var/log/slim.log
118 '';
119 environment =
120 { SLIM_CFGFILE = slimConfig;
121 SLIM_THEMESDIR = slimThemesDir;
122 };
123 execCmd = "exec ${pkgs.slim}/bin/slim";
124 };
125
126 services.xserver.displayManager.sessionCommands =
127 ''
128 # Export the config/themes for slimlock.
129 export SLIM_THEMESDIR=${slimThemesDir}
130 '';
131
132 # Allow null passwords so that the user can login as root on the
133 # installation CD.
134 security.pam.services.slim = { allowNullPassword = true; startSession = true; };
135
136 # Allow slimlock to work.
137 security.pam.services.slimlock = {};
138
139 environment.systemPackages = [ pkgs.slim ];
140
141 };
142
143}