@@ -6,9 +6,14 @@ 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}''}
1419 ${optionalString (cfg.nodeName != null) ''nodeName=${cfg.nodeName}''}
@@ -159,6 +164,25 @@ in
159164 '';
160165 };
161166
167+ stateSaveLocation = mkOption {
168+ type = types.str;
169+ default = "/var/spool/slurmctld";
170+ description = ''
171+ Directory into which the Slurm controller, slurmctld, saves its state.
172+ '';
173+ };
174+
175+ user = mkOption {
176+ type = types.str;
177+ default = defaultUser;
178+ description = ''
179+ Set this option when you want to run the slurmctld daemon
180+ as something else than the default slurm user "slurm".
181+ Note that the UID of this user needs to be the same
182+ on all nodes.
183+ '';
184+ };
185+
162186 extraConfig = mkOption {
163187 default = "";
164188 type = types.lines;
@@ -226,6 +250,15 @@ in
226250
227251 services.munge.enable = mkDefault true;
228252
253+ # use a static uid as default to ensure it is the same on all nodes
254+ users.users.slurm = mkIf (cfg.user == defaultUser) {
255+ name = defaultUser;
256+ group = "slurm";
257+ uid = config.ids.uids.slurm;
258+ };
259+
260+ users.groups.slurm.gid = config.ids.uids.slurm;
261+
229262 systemd.services.slurmd = mkIf (cfg.client.enable) {
230263 path = with pkgs; [ wrappedSlurm coreutils ]
231264 ++ lib.optional cfg.enableSrunX11 slurm-spank-x11;
@@ -261,6 +294,11 @@ in
261294 PIDFile = "/run/slurmctld.pid";
262295 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
263296 };
297+
298+ preStart = ''
299+ mkdir -p ${cfg.stateSaveLocation}
300+ chown -R ${cfg.user}:slurm ${cfg.stateSaveLocation}
301+ '';
264302 };
265303
266304 };