refactor: update slurm config to separate out client and server behaviors
Some checks failed
ci / treefmt (push) Failing after 5s

This commit is contained in:
Ceferino Patino 2026-07-06 12:30:00 -05:00
commit 35a5051ade
Signed by: c4patino
SSH key fingerprint: SHA256:Wu+cU1t+7zVT9wzew/4meNmeulo66NzMqc22MdDBgXI
3 changed files with 74 additions and 39 deletions

View file

@ -0,0 +1,40 @@
{
config,
inputs,
lib,
namespace,
...
}: let
inherit (lib) mkIf mkAfter optionalString;
inherit (lib.${namespace}) getAttrByNamespace mkPersistDir;
base = "${namespace}.services.apps.slurm";
cfg = getAttrByNamespace config base;
inherit (config.networking) hostName;
in {
config = mkIf (builtins.hasAttr hostName cfg.nodeMap) {
services.slurm = {
client.enable = true;
extraConfig = mkAfter ''
SlurmdParameters=allow_ecores
TaskProlog=${inputs.dotfiles + "/slurm/prolog.sh"}
TaskEpilog=${inputs.dotfiles + "/slurm/epilog.sh"}
'';
extraCgroupConfig = ''
ConstrainCores=yes
ConstrainDevices=yes
ConstrainRAMSpace=yes
''
+ optionalString (hostName != "chibi") ''
ConstrainSwapSpace=yes
AllowedSwapSpace=0
'';
};
${namespace}.services.storage.impermanence.folders = [
(mkPersistDir config "slurm" "/var/spool/slurmd")
];
};
}

View file

@ -7,11 +7,15 @@
}: let }: let
inherit (lib) types mkEnableOption mkIf groupBy mapAttrsToList attrNames mapAttrs concatStringsSep flatten; inherit (lib) types mkEnableOption mkIf groupBy mapAttrsToList attrNames mapAttrs concatStringsSep flatten;
inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace resolveHostIP mkOpt mkOptAttrset mkListOpt mkPersistDir; inherit (lib.${namespace}) getAttrByNamespace mkOptionsWithNamespace resolveHostIP mkOpt mkOptAttrset mkListOpt mkPersistDir;
inherit (config.networking) hostName;
base = "${namespace}.services.apps.slurm"; base = "${namespace}.services.apps.slurm";
cfg = getAttrByNamespace config base; cfg = getAttrByNamespace config base;
networkCfg = getAttrByNamespace config "${namespace}.services.networking"; networkCfg = getAttrByNamespace config "${namespace}.services.networking";
in { in {
imports = [
./client.nix
./server.nix
];
options = with types; options = with types;
mkOptionsWithNamespace base { mkOptionsWithNamespace base {
enable = mkEnableOption "SLURM"; enable = mkEnableOption "SLURM";
@ -27,11 +31,6 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
services = { services = {
slurm = { slurm = {
client.enable = builtins.hasAttr hostName cfg.nodeMap;
server.enable = builtins.elem hostName cfg.controlHosts;
stateSaveLocation = "/mnt/nfs/slurm";
nodeName = let nodeName = let
mkNodeConfig = node: info: "${node} NodeAddr=${resolveHostIP networkCfg.devices node} ${info.configString} State=UNKNOWN"; mkNodeConfig = node: info: "${node} NodeAddr=${resolveHostIP networkCfg.devices node} ${info.configString} State=UNKNOWN";
in in
@ -61,39 +60,19 @@ in {
|> mapAttrsToList formatPartition; |> mapAttrsToList formatPartition;
extraConfig = let extraConfig = let
mkHostString = host: "SlurmctldHost=${host}(${resolveHostIP networkCfg.devices host})";
hostStrings = hostStrings =
cfg.controlHosts cfg.controlHosts
|> map mkHostString |> map (host: "SlurmctldHost=${host}(${resolveHostIP networkCfg.devices host})")
|> concatStringsSep "\n"; |> concatStringsSep "\n";
in '' in ''
${hostStrings} ${hostStrings}
GresTypes=gpu,shard GresTypes=gpu,shard
TaskPlugin=task/cgroup TaskPlugin=task/cgroup
SlurmdParameters=allow_ecores
DefCpuPerGPU=1 DefCpuPerGPU=1
DefMemPerCPU=1000 DefMemPerCPU=1000
ReturnToService=2 ReturnToService=2
TaskProlog=${inputs.dotfiles + "/slurm/prolog.sh"}
TaskEpilog=${inputs.dotfiles + "/slurm/epilog.sh"}
''; '';
extraCgroupConfig =
''
ConstrainCores=yes
ConstrainDevices=yes
ConstrainRAMSpace=yes
''
+ (
if hostName != "chibi"
then ''
ConstrainSwapSpace=yes
AllowedSwapSpace=0
''
else ''''
);
extraConfigPaths = [(inputs.dotfiles + "/slurm/config")]; extraConfigPaths = [(inputs.dotfiles + "/slurm/config")];
}; };
@ -103,16 +82,6 @@ in {
}; };
}; };
systemd.services.slurmctld = mkIf (builtins.elem hostName cfg.controlHosts) {
requires = [
"mnt-nfs-slurm.mount"
];
after = [
"mnt-nfs-slurm.mount"
];
};
sops.secrets = let sops.secrets = let
inherit (config.users.users) munge; inherit (config.users.users) munge;
in { in {
@ -126,8 +95,6 @@ in {
}; };
${namespace}.services.storage.impermanence.folders = [ ${namespace}.services.storage.impermanence.folders = [
(mkPersistDir config "slurm" "/var/spool/slurmctld")
(mkPersistDir config "slurm" "/var/spool/slurmd")
(mkPersistDir config "munge" "/var/lib/munge") (mkPersistDir config "munge" "/var/lib/munge")
]; ];
}; };

View file

@ -0,0 +1,28 @@
{
config,
lib,
namespace,
...
}: let
inherit (lib) mkIf;
inherit (lib.${namespace}) getAttrByNamespace mkPersistDir;
base = "${namespace}.services.apps.slurm";
cfg = getAttrByNamespace config base;
inherit (config.networking) hostName;
in {
config = mkIf (builtins.elem hostName cfg.controlHosts) {
services.slurm = {
server.enable = true;
stateSaveLocation = "/mnt/nfs/slurm";
};
systemd.services.slurmctld = {
requires = ["mnt-nfs-slurm.mount"];
after = ["mnt-nfs-slurm.mount"];
};
${namespace}.services.storage.impermanence.folders = [
(mkPersistDir config "slurm" "/var/spool/slurmctld")
];
};
}