2015-03-01 01:12:13 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.slurm;
|
|
|
|
# configuration file can be generated by http://slurm.schedmd.com/configurator.html
|
2018-10-23 22:43:53 +01:00
|
|
|
|
|
|
|
defaultUser = "slurm";
|
|
|
|
|
2018-05-24 19:16:01 +01:00
|
|
|
configFile = pkgs.writeTextDir "slurm.conf"
|
2015-03-01 01:12:13 +00:00
|
|
|
''
|
2018-09-02 01:37:29 +01:00
|
|
|
ClusterName=${cfg.clusterName}
|
2018-10-23 22:43:53 +01:00
|
|
|
StateSaveLocation=${cfg.stateSaveLocation}
|
|
|
|
SlurmUser=${cfg.user}
|
2015-03-01 21:48:20 +00:00
|
|
|
${optionalString (cfg.controlMachine != null) ''controlMachine=${cfg.controlMachine}''}
|
|
|
|
${optionalString (cfg.controlAddr != null) ''controlAddr=${cfg.controlAddr}''}
|
2018-10-25 19:34:17 +01:00
|
|
|
${toString (map (x: "NodeName=${x}\n") cfg.nodeName)}
|
|
|
|
${toString (map (x: "PartitionName=${x}\n") cfg.partitionName)}
|
2019-11-05 21:00:23 +00:00
|
|
|
PlugStackConfig=${plugStackConfig}/plugstack.conf
|
2018-05-22 12:55:13 +01:00
|
|
|
ProctrackType=${cfg.procTrackType}
|
2015-03-01 21:48:20 +00:00
|
|
|
${cfg.extraConfig}
|
2015-03-01 01:12:13 +00:00
|
|
|
'';
|
2017-12-17 08:25:31 +00:00
|
|
|
|
2018-05-24 19:16:01 +01:00
|
|
|
plugStackConfig = pkgs.writeTextDir "plugstack.conf"
|
2017-12-17 08:25:31 +00:00
|
|
|
''
|
|
|
|
${optionalString cfg.enableSrunX11 ''optional ${pkgs.slurm-spank-x11}/lib/x11.so''}
|
2018-05-24 19:16:01 +01:00
|
|
|
${cfg.extraPlugstackConfig}
|
2017-12-17 08:25:31 +00:00
|
|
|
'';
|
2018-05-24 19:16:01 +01:00
|
|
|
|
|
|
|
cgroupConfig = pkgs.writeTextDir "cgroup.conf"
|
|
|
|
''
|
|
|
|
${cfg.extraCgroupConfig}
|
|
|
|
'';
|
|
|
|
|
2018-09-15 12:09:36 +01:00
|
|
|
slurmdbdConf = pkgs.writeTextDir "slurmdbd.conf"
|
|
|
|
''
|
|
|
|
DbdHost=${cfg.dbdserver.dbdHost}
|
|
|
|
SlurmUser=${cfg.user}
|
|
|
|
StorageType=accounting_storage/mysql
|
2019-11-10 20:28:09 +00:00
|
|
|
StorageUser=${cfg.dbdserver.storageUser}
|
|
|
|
${optionalString (cfg.dbdserver.storagePass != null) "StoragePass=${cfg.dbdserver.storagePass}"}
|
2018-09-15 12:09:36 +01:00
|
|
|
${cfg.dbdserver.extraConfig}
|
|
|
|
'';
|
|
|
|
|
2018-05-24 19:16:01 +01:00
|
|
|
# slurm expects some additional config files to be
|
|
|
|
# in the same directory as slurm.conf
|
|
|
|
etcSlurm = pkgs.symlinkJoin {
|
|
|
|
name = "etc-slurm";
|
2018-11-06 22:48:01 +00:00
|
|
|
paths = [ configFile cgroupConfig plugStackConfig ] ++ cfg.extraConfigPaths;
|
2018-05-24 19:16:01 +01:00
|
|
|
};
|
2015-03-01 01:12:13 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2018-10-25 20:03:23 +01:00
|
|
|
meta.maintainers = [ maintainers.markuskowa ];
|
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.slurm = {
|
|
|
|
|
|
|
|
server = {
|
2018-05-24 10:10:20 +01:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Wether to enable the slurm control daemon.
|
|
|
|
Note that the standard authentication method is "munge".
|
|
|
|
The "munge" service needs to be provided with a password file in order for
|
2018-05-24 21:56:57 +01:00
|
|
|
slurm to work properly (see <literal>services.munge.password</literal>).
|
2018-05-24 10:10:20 +01:00
|
|
|
'';
|
|
|
|
};
|
2015-03-01 01:12:13 +00:00
|
|
|
};
|
2017-12-17 08:25:31 +00:00
|
|
|
|
2018-09-15 12:09:36 +01:00
|
|
|
dbdserver = {
|
|
|
|
enable = mkEnableOption "SlurmDBD service";
|
|
|
|
|
|
|
|
dbdHost = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
|
|
|
description = ''
|
|
|
|
Hostname of the machine where <literal>slurmdbd</literal>
|
|
|
|
is running (i.e. name returned by <literal>hostname -s</literal>).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-11-10 20:28:09 +00:00
|
|
|
storageUser = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.user;
|
|
|
|
description = ''
|
|
|
|
Database user name.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
storagePass = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Database password. Note that this password will be publicable
|
|
|
|
readable in the nix store. Use <option>configFile</option>
|
|
|
|
to store the and config file and password outside the nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Path to <literal>slurmdbd.conf</literal>. The password for the database connection
|
|
|
|
is stored in the config file. Use this option to specfify a path
|
|
|
|
outside the nix store. If this option is unset a configuration file
|
|
|
|
will be generated. See also:
|
|
|
|
<citerefentry><refentrytitle>slurmdbd.conf</refentrytitle>
|
|
|
|
<manvolnum>8</manvolnum></citerefentry>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-15 12:09:36 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration for <literal>slurmdbd.conf</literal>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
client = {
|
2018-05-24 10:10:20 +01:00
|
|
|
enable = mkEnableOption "slurm client daemon";
|
2018-05-24 19:16:01 +01:00
|
|
|
};
|
2015-03-01 01:12:13 +00:00
|
|
|
|
2018-05-24 19:16:01 +01:00
|
|
|
enableStools = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Wether to provide a slurm.conf file.
|
|
|
|
Enable this option if you do not run a slurm daemon on this host
|
|
|
|
(i.e. <literal>server.enable</literal> and <literal>client.enable</literal> are <literal>false</literal>)
|
|
|
|
but you still want to run slurm commands from this host.
|
|
|
|
'';
|
2015-03-01 01:12:13 +00:00
|
|
|
};
|
|
|
|
|
2015-12-25 14:54:35 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2019-11-05 21:00:23 +00:00
|
|
|
default = pkgs.slurm.override { enableX11 = ! cfg.enableSrunX11; };
|
2017-07-13 02:35:54 +01:00
|
|
|
defaultText = "pkgs.slurm";
|
|
|
|
example = literalExample "pkgs.slurm-full";
|
2015-12-25 14:54:35 +00:00
|
|
|
description = ''
|
2016-05-28 00:30:02 +01:00
|
|
|
The package to use for slurm binaries.
|
2015-12-25 14:54:35 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-03-01 21:48:20 +00:00
|
|
|
controlMachine = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = null;
|
|
|
|
description = ''
|
|
|
|
The short hostname of the machine where SLURM control functions are
|
|
|
|
executed (i.e. the name returned by the command "hostname -s", use "tux001"
|
|
|
|
rather than "tux001.my.com").
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
controlAddr = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = cfg.controlMachine;
|
|
|
|
example = null;
|
|
|
|
description = ''
|
|
|
|
Name that ControlMachine should be referred to in establishing a
|
|
|
|
communications path.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-02 01:37:29 +01:00
|
|
|
clusterName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "default";
|
|
|
|
example = "myCluster";
|
|
|
|
description = ''
|
|
|
|
Necessary to distinguish accounting records in a multi-cluster environment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-03-01 21:48:20 +00:00
|
|
|
nodeName = mkOption {
|
2018-10-25 19:34:17 +01:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = literalExample ''[ "linux[1-32] CPUs=1 State=UNKNOWN" ];'';
|
2015-03-01 21:48:20 +00:00
|
|
|
description = ''
|
|
|
|
Name that SLURM uses to refer to a node (or base partition for BlueGene
|
|
|
|
systems). Typically this would be the string that "/bin/hostname -s"
|
|
|
|
returns. Note that now you have to write node's parameters after the name.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
partitionName = mkOption {
|
2018-10-25 19:34:17 +01:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = literalExample ''[ "debug Nodes=linux[1-32] Default=YES MaxTime=INFINITE State=UP" ];'';
|
2015-03-01 21:48:20 +00:00
|
|
|
description = ''
|
|
|
|
Name by which the partition may be referenced. Note that now you have
|
2018-05-24 19:16:01 +01:00
|
|
|
to write the partition's parameters after the name.
|
2015-03-01 21:48:20 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-17 08:25:31 +00:00
|
|
|
enableSrunX11 = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
If enabled srun will accept the option "--x11" to allow for X11 forwarding
|
|
|
|
from within an interactive session or a batch job. This activates the
|
2018-05-24 19:16:01 +01:00
|
|
|
slurm-spank-x11 module. Note that this option also enables
|
2019-11-05 21:00:23 +00:00
|
|
|
<option>services.openssh.forwardX11</option> on the client.
|
2018-05-26 10:51:45 +01:00
|
|
|
|
|
|
|
This option requires slurm to be compiled without native X11 support.
|
2019-11-05 21:00:23 +00:00
|
|
|
The default behavior is to re-compile the slurm package with native X11
|
|
|
|
support disabled if this option is set to true.
|
|
|
|
|
|
|
|
To use the native X11 support add <literal>PrologFlags=X11</literal> in <option>extraConfig</option>.
|
|
|
|
Note that this method will only work RSA SSH host keys.
|
2017-12-17 08:25:31 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-05-22 12:55:13 +01:00
|
|
|
procTrackType = mkOption {
|
2018-10-23 23:08:39 +01:00
|
|
|
type = types.str;
|
2018-05-22 12:55:13 +01:00
|
|
|
default = "proctrack/linuxproc";
|
|
|
|
description = ''
|
|
|
|
Plugin to be used for process tracking on a job step basis.
|
|
|
|
The slurmd daemon uses this mechanism to identify all processes
|
|
|
|
which are children of processes it spawns for a user job step.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-10-23 22:43:53 +01:00
|
|
|
stateSaveLocation = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/spool/slurmctld";
|
|
|
|
description = ''
|
|
|
|
Directory into which the Slurm controller, slurmctld, saves its state.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = defaultUser;
|
|
|
|
description = ''
|
|
|
|
Set this option when you want to run the slurmctld daemon
|
|
|
|
as something else than the default slurm user "slurm".
|
|
|
|
Note that the UID of this user needs to be the same
|
|
|
|
on all nodes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
extraConfig = mkOption {
|
2017-12-17 08:25:31 +00:00
|
|
|
default = "";
|
2015-03-01 01:12:13 +00:00
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
Extra configuration options that will be added verbatim at
|
|
|
|
the end of the slurm configuration file.
|
|
|
|
'';
|
|
|
|
};
|
2018-05-24 19:16:01 +01:00
|
|
|
|
|
|
|
extraPlugstackConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
Extra configuration that will be added to the end of <literal>plugstack.conf</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraCgroupConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
Extra configuration for <literal>cgroup.conf</literal>. This file is
|
|
|
|
used when <literal>procTrackType=proctrack/cgroup</literal>.
|
|
|
|
'';
|
|
|
|
};
|
2018-09-15 12:09:36 +01:00
|
|
|
|
2018-11-06 22:48:01 +00:00
|
|
|
extraConfigPaths = mkOption {
|
|
|
|
type = with types; listOf path;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Slurm expects config files for plugins in the same path
|
|
|
|
as <literal>slurm.conf</literal>. Add extra nix store
|
|
|
|
paths that should be merged into same directory as
|
|
|
|
<literal>slurm.conf</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-15 12:09:36 +01:00
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2015-12-25 14:54:35 +00:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
wrappedSlurm = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "wrappedSlurm";
|
|
|
|
|
|
|
|
builder = pkgs.writeText "builder.sh" ''
|
|
|
|
source $stdenv/setup
|
|
|
|
mkdir -p $out/bin
|
2016-05-28 00:30:19 +01:00
|
|
|
find ${getBin cfg.package}/bin -type f -executable | while read EXE
|
2015-12-25 14:54:35 +00:00
|
|
|
do
|
|
|
|
exename="$(basename $EXE)"
|
|
|
|
wrappername="$out/bin/$exename"
|
|
|
|
cat > "$wrappername" <<EOT
|
|
|
|
#!/bin/sh
|
|
|
|
if [ -z "$SLURM_CONF" ]
|
|
|
|
then
|
2018-05-24 19:16:01 +01:00
|
|
|
SLURM_CONF="${etcSlurm}/slurm.conf" "$EXE" "\$@"
|
2015-12-25 14:54:35 +00:00
|
|
|
else
|
|
|
|
"$EXE" "\$0"
|
|
|
|
fi
|
|
|
|
EOT
|
|
|
|
chmod +x "$wrappername"
|
|
|
|
done
|
2018-06-01 21:02:16 +01:00
|
|
|
|
|
|
|
mkdir -p $out/share
|
|
|
|
ln -s ${getBin cfg.package}/share/man $out/share/man
|
2015-12-25 14:54:35 +00:00
|
|
|
'';
|
|
|
|
};
|
2015-03-01 01:12:13 +00:00
|
|
|
|
2018-09-15 12:09:36 +01:00
|
|
|
in mkIf ( cfg.enableStools ||
|
|
|
|
cfg.client.enable ||
|
|
|
|
cfg.server.enable ||
|
|
|
|
cfg.dbdserver.enable ) {
|
2015-12-25 14:54:35 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ wrappedSlurm ];
|
2015-03-01 01:12:13 +00:00
|
|
|
|
2018-05-24 10:10:20 +01:00
|
|
|
services.munge.enable = mkDefault true;
|
|
|
|
|
2018-10-23 22:43:53 +01:00
|
|
|
# use a static uid as default to ensure it is the same on all nodes
|
|
|
|
users.users.slurm = mkIf (cfg.user == defaultUser) {
|
|
|
|
name = defaultUser;
|
|
|
|
group = "slurm";
|
|
|
|
uid = config.ids.uids.slurm;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.slurm.gid = config.ids.uids.slurm;
|
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
systemd.services.slurmd = mkIf (cfg.client.enable) {
|
2017-12-17 08:25:31 +00:00
|
|
|
path = with pkgs; [ wrappedSlurm coreutils ]
|
|
|
|
++ lib.optional cfg.enableSrunX11 slurm-spank-x11;
|
2015-03-01 21:48:20 +00:00
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "systemd-tmpfiles-clean.service" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
2018-11-06 12:04:42 +00:00
|
|
|
KillMode = "process";
|
2015-12-25 14:54:35 +00:00
|
|
|
ExecStart = "${wrappedSlurm}/bin/slurmd";
|
2015-03-01 01:12:13 +00:00
|
|
|
PIDFile = "/run/slurmd.pid";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
2020-02-10 01:14:03 +00:00
|
|
|
LimitMEMLOCK = "infinity";
|
2015-03-01 01:12:13 +00:00
|
|
|
};
|
2015-12-25 14:54:35 +00:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p /var/spool
|
|
|
|
'';
|
2015-03-01 01:12:13 +00:00
|
|
|
};
|
|
|
|
|
2018-05-24 19:16:01 +01:00
|
|
|
services.openssh.forwardX11 = mkIf cfg.client.enable (mkDefault true);
|
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
systemd.services.slurmctld = mkIf (cfg.server.enable) {
|
2017-12-17 08:25:31 +00:00
|
|
|
path = with pkgs; [ wrappedSlurm munge coreutils ]
|
|
|
|
++ lib.optional cfg.enableSrunX11 slurm-spank-x11;
|
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2015-12-25 14:54:35 +00:00
|
|
|
after = [ "network.target" "munged.service" ];
|
2015-03-01 01:12:13 +00:00
|
|
|
requires = [ "munged.service" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
2015-12-25 14:54:35 +00:00
|
|
|
ExecStart = "${wrappedSlurm}/bin/slurmctld";
|
2015-03-01 01:12:13 +00:00
|
|
|
PIDFile = "/run/slurmctld.pid";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
};
|
2018-10-23 22:43:53 +01:00
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${cfg.stateSaveLocation}
|
|
|
|
chown -R ${cfg.user}:slurm ${cfg.stateSaveLocation}
|
|
|
|
'';
|
2015-03-01 01:12:13 +00:00
|
|
|
};
|
|
|
|
|
2018-09-15 12:09:36 +01:00
|
|
|
systemd.services.slurmdbd = mkIf (cfg.dbdserver.enable) {
|
|
|
|
path = with pkgs; [ wrappedSlurm munge coreutils ];
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" "munged.service" "mysql.service" ];
|
|
|
|
requires = [ "munged.service" "mysql.service" ];
|
|
|
|
|
|
|
|
# slurm strips the last component off the path
|
2019-11-10 20:28:09 +00:00
|
|
|
environment.SLURM_CONF =
|
|
|
|
if (cfg.dbdserver.configFile == null) then
|
|
|
|
"${slurmdbdConf}/slurm.conf"
|
|
|
|
else
|
|
|
|
cfg.dbdserver.configFile;
|
2018-09-15 12:09:36 +01:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
ExecStart = "${cfg.package}/bin/slurmdbd";
|
|
|
|
PIDFile = "/run/slurmdbd.pid";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-01 01:12:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|