1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/nixos/modules/services/computing/slurm/slurm.nix

172 lines
4.6 KiB
Nix
Raw Normal View History

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
configFile = pkgs.writeText "slurm.conf"
''
2015-03-01 21:48:20 +00:00
${optionalString (cfg.controlMachine != null) ''controlMachine=${cfg.controlMachine}''}
${optionalString (cfg.controlAddr != null) ''controlAddr=${cfg.controlAddr}''}
${optionalString (cfg.nodeName != null) ''nodeName=${cfg.nodeName}''}
${optionalString (cfg.partitionName != null) ''partitionName=${cfg.partitionName}''}
${cfg.extraConfig}
2015-03-01 01:12:13 +00:00
'';
in
{
###### interface
options = {
services.slurm = {
server = {
2015-03-01 21:48:20 +00:00
enable = mkEnableOption "slurm control daemon";
2015-03-01 01:12:13 +00:00
};
client = {
2015-03-01 21:48:20 +00:00
enable = mkEnableOption "slurm rlient daemon";
2015-03-01 01:12:13 +00:00
};
2015-12-25 14:54:35 +00:00
package = mkOption {
type = types.package;
default = pkgs.slurm;
defaultText = "pkgs.slurm";
example = literalExample "pkgs.slurm-full";
2015-12-25 14:54:35 +00:00
description = ''
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.
'';
};
nodeName = mkOption {
type = types.nullOr types.str;
default = null;
example = "linux[1-32] CPUs=1 State=UNKNOWN";
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 {
type = types.nullOr types.str;
default = null;
example = "debug Nodes=linux[1-32] Default=YES MaxTime=INFINITE State=UP";
description = ''
Name by which the partition may be referenced. Note that now you have
to write patrition's parameters after the name.
'';
};
2015-03-01 01:12:13 +00:00
extraConfig = mkOption {
default = "";
type = types.lines;
description = ''
Extra configuration options that will be added verbatim at
the end of the slurm configuration file.
'';
};
};
};
###### implementation
2015-12-25 14:54:35 +00:00
config =
let
wrappedSlurm = pkgs.stdenv.mkDerivation {
name = "wrappedSlurm";
propagatedBuildInputs = [ cfg.package configFile ];
builder = pkgs.writeText "builder.sh" ''
source $stdenv/setup
mkdir -p $out/bin
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
SLURM_CONF="${configFile}" "$EXE" "\$@"
else
"$EXE" "\$0"
fi
EOT
chmod +x "$wrappername"
done
'';
};
2015-03-01 01:12:13 +00:00
2015-12-25 14:54:35 +00:00
in mkIf (cfg.client.enable || cfg.server.enable) {
environment.systemPackages = [ wrappedSlurm ];
2015-03-01 01:12:13 +00:00
systemd.services.slurmd = mkIf (cfg.client.enable) {
2015-12-25 14:54:35 +00:00
path = with pkgs; [ wrappedSlurm coreutils ];
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";
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";
};
2015-12-25 14:54:35 +00:00
preStart = ''
mkdir -p /var/spool
'';
2015-03-01 01:12:13 +00:00
};
systemd.services.slurmctld = mkIf (cfg.server.enable) {
2015-12-25 14:54:35 +00:00
path = with pkgs; [ wrappedSlurm munge coreutils ];
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";
};
};
};
}