@@ -6,13 +6,18 @@ let
66
77 cfg = config.services.slurm;
88 # configuration file can be generated by http://slurm.schedmd.com/configurator.html
9+
10+ defaultUser = "slurm";
11+
912 configFile = pkgs.writeTextDir "slurm.conf"
1013 ''
1114 ClusterName=${cfg.clusterName}
15+ StateSaveLocation=${cfg.stateSaveLocation}
16+ SlurmUser=${cfg.user}
1217 ${optionalString (cfg.controlMachine != null) ''controlMachine=${cfg.controlMachine}''}
1318 ${optionalString (cfg.controlAddr != null) ''controlAddr=${cfg.controlAddr}''}
14− ${optionalString (cfg.nodeName != null) ''nodeName=${cfg.nodeName}''}
15− ${optionalString (cfg.partitionName != null) ''partitionName=${cfg.partitionName}''}
19+ ${toString (map (x: "NodeName=${x}\n") cfg.nodeName)}
20+ ${toString (map (x: "PartitionName=${x}\n") cfg.partitionName)}
1621 PlugStackConfig=${plugStackConfig}
1722 ProctrackType=${cfg.procTrackType}
1823 ${cfg.extraConfig}
@@ -24,12 +29,19 @@ let
2429 ${cfg.extraPlugstackConfig}
2530 '';
2631
27−
2832 cgroupConfig = pkgs.writeTextDir "cgroup.conf"
2933 ''
3034 ${cfg.extraCgroupConfig}
3135 '';
3236
37+ slurmdbdConf = pkgs.writeTextDir "slurmdbd.conf"
38+ ''
39+ DbdHost=${cfg.dbdserver.dbdHost}
40+ SlurmUser=${cfg.user}
41+ StorageType=accounting_storage/mysql
42+ ${cfg.dbdserver.extraConfig}
43+ '';
44+
3345 # slurm expects some additional config files to be
3446 # in the same directory as slurm.conf
3547 etcSlurm = pkgs.symlinkJoin {
@@ -43,6 +55,8 @@ in
4355
4456 ###### interface
4557
58+ meta.maintainers = [ maintainers.markuskowa ];
59+
4660 options = {
4761
4862 services.slurm = {
@@ -60,6 +74,27 @@ in
6074 };
6175 };
6276
77+ dbdserver = {
78+ enable = mkEnableOption "SlurmDBD service";
79+
80+ dbdHost = mkOption {
81+ type = types.str;
82+ default = config.networking.hostName;
83+ description = ''
84+ Hostname of the machine where <literal>slurmdbd</literal>
85+ is running (i.e. name returned by <literal>hostname -s</literal>).
86+ '';
87+ };
88+
89+ extraConfig = mkOption {
90+ type = types.lines;
91+ default = "";
92+ description = ''
93+ Extra configuration for <literal>slurmdbd.conf</literal>
94+ '';
95+ };
96+ };
97+
6398 client = {
6499 enable = mkEnableOption "slurm client daemon";
65100 };
@@ -116,9 +151,9 @@ in
116151 };
117152
118153 nodeName = mkOption {
119− type = types.nullOr types.str;
120− default = null;
121− example = "linux[1-32] CPUs=1 State=UNKNOWN";
154+ type = types.listOf types.str;
155+ default = [];
156+ example = literalExample ''[ "linux[1-32] CPUs=1 State=UNKNOWN" ];'';
122157 description = ''
123158 Name that SLURM uses to refer to a node (or base partition for BlueGene
124159 systems). Typically this would be the string that "/bin/hostname -s"
@@ -127,9 +162,9 @@ in
127162 };
128163
129164 partitionName = mkOption {
130− type = types.nullOr types.str;
131− default = null;
132− example = "debug Nodes=linux[1-32] Default=YES MaxTime=INFINITE State=UP";
165+ type = types.listOf types.str;
166+ default = [];
167+ example = literalExample ''[ "debug Nodes=linux[1-32] Default=YES MaxTime=INFINITE State=UP" ];'';
133168 description = ''
134169 Name by which the partition may be referenced. Note that now you have
135170 to write the partition's parameters after the name.
@@ -150,7 +185,7 @@ in
150185 };
151186
152187 procTrackType = mkOption {
153− type = types.string;
188+ type = types.str;
154189 default = "proctrack/linuxproc";
155190 description = ''
156191 Plugin to be used for process tracking on a job step basis.
@@ -159,6 +194,25 @@ in
159194 '';
160195 };
161196
197+ stateSaveLocation = mkOption {
198+ type = types.str;
199+ default = "/var/spool/slurmctld";
200+ description = ''
201+ Directory into which the Slurm controller, slurmctld, saves its state.
202+ '';
203+ };
204+
205+ user = mkOption {
206+ type = types.str;
207+ default = defaultUser;
208+ description = ''
209+ Set this option when you want to run the slurmctld daemon
210+ as something else than the default slurm user "slurm".
211+ Note that the UID of this user needs to be the same
212+ on all nodes.
213+ '';
214+ };
215+
162216 extraConfig = mkOption {
163217 default = "";
164218 type = types.lines;
@@ -184,6 +238,8 @@ in
184238 used when <literal>procTrackType=proctrack/cgroup</literal>.
185239 '';
186240 };
241+
242+
187243 };
188244
189245 };
@@ -220,12 +276,24 @@ in
220276 '';
221277 };
222278
223− in mkIf (cfg.enableStools || cfg.client.enable || cfg.server.enable) {
279+ in mkIf ( cfg.enableStools ||
280+ cfg.client.enable ||
281+ cfg.server.enable ||
282+ cfg.dbdserver.enable ) {
224283
225284 environment.systemPackages = [ wrappedSlurm ];
226285
227286 services.munge.enable = mkDefault true;
228287
288+ # use a static uid as default to ensure it is the same on all nodes
289+ users.users.slurm = mkIf (cfg.user == defaultUser) {
290+ name = defaultUser;
291+ group = "slurm";
292+ uid = config.ids.uids.slurm;
293+ };
294+
295+ users.groups.slurm.gid = config.ids.uids.slurm;
296+
229297 systemd.services.slurmd = mkIf (cfg.client.enable) {
230298 path = with pkgs; [ wrappedSlurm coreutils ]
231299 ++ lib.optional cfg.enableSrunX11 slurm-spank-x11;
@@ -261,6 +329,29 @@ in
261329 PIDFile = "/run/slurmctld.pid";
262330 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
263331 };
332+
333+ preStart = ''
334+ mkdir -p ${cfg.stateSaveLocation}
335+ chown -R ${cfg.user}:slurm ${cfg.stateSaveLocation}
336+ '';
337+ };
338+
339+ systemd.services.slurmdbd = mkIf (cfg.dbdserver.enable) {
340+ path = with pkgs; [ wrappedSlurm munge coreutils ];
341+
342+ wantedBy = [ "multi-user.target" ];
343+ after = [ "network.target" "munged.service" "mysql.service" ];
344+ requires = [ "munged.service" "mysql.service" ];
345+
346+ # slurm strips the last component off the path
347+ environment.SLURM_CONF = "${slurmdbdConf}/slurm.conf";
348+
349+ serviceConfig = {
350+ Type = "forking";
351+ ExecStart = "${cfg.package}/bin/slurmdbd";
352+ PIDFile = "/run/slurmdbd.pid";
353+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
354+ };
264355 };
265356
266357 };