From ae93ed0f0d4e7be0a286d1fca86446318c0c6ffb Mon Sep 17 00:00:00 2001
From: Markus Kowalewski <markus.kowalewski@fysik.su.se>
Date: Tue, 6 Nov 2018 13:04:42 +0100
Subject: [PATCH 1/4] nixos/slurm: set slurmd KillMode to process

The default of systemd is to kill the
the whole cgroup of a service. For slurmd
this means that all running jobs get killed
as well whenever the configuration is updated (and activated).

To avoid this behaviour we set "KillMode=process"
to kill only slurmd on reload. This is how
slurm configures the systemd service.

See:
https://bugs.schedmd.com/show_bug.cgi?id=2095#c24
https://github.com/SchedMD/slurm/commit/508f866ea10e4c359d62d443279198082d587107
---
 nixos/modules/services/computing/slurm/slurm.nix | 1 +
 1 file changed, 1 insertion(+)

diff --git a/nixos/modules/services/computing/slurm/slurm.nix b/nixos/modules/services/computing/slurm/slurm.nix
index cd481212db2d..cd1b6264fa92 100644
--- a/nixos/modules/services/computing/slurm/slurm.nix
+++ b/nixos/modules/services/computing/slurm/slurm.nix
@@ -303,6 +303,7 @@ in
 
       serviceConfig = {
         Type = "forking";
+        KillMode = "process";
         ExecStart = "${wrappedSlurm}/bin/slurmd";
         PIDFile = "/run/slurmd.pid";
         ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";

From 25af5188454a7ce35e11366f8102b0698f72ebea Mon Sep 17 00:00:00 2001
From: Markus Kowalewski <markus.kowalewski@gmail.com>
Date: Tue, 6 Nov 2018 23:48:01 +0100
Subject: [PATCH 2/4] nixos/slurm: add extraConfigPaths options

---
 nixos/modules/services/computing/slurm/slurm.nix | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/nixos/modules/services/computing/slurm/slurm.nix b/nixos/modules/services/computing/slurm/slurm.nix
index cd1b6264fa92..d1a1383e45b0 100644
--- a/nixos/modules/services/computing/slurm/slurm.nix
+++ b/nixos/modules/services/computing/slurm/slurm.nix
@@ -46,7 +46,7 @@ let
   # in the same directory as slurm.conf
   etcSlurm = pkgs.symlinkJoin {
     name = "etc-slurm";
-    paths = [ configFile cgroupConfig plugStackConfig ];
+    paths = [ configFile cgroupConfig plugStackConfig ] ++ cfg.extraConfigPaths;
   };
 
 in
@@ -239,6 +239,17 @@ in
         '';
       };
 
+      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>.
+        '';
+      };
+
 
     };
 

From 0ed4fc606ae0ee92113fe72f17cf3ee5381bd8f8 Mon Sep 17 00:00:00 2001
From: Markus Kowalewski <markus.kowalewski@fysik.su.se>
Date: Thu, 22 Nov 2018 13:21:37 +0100
Subject: [PATCH 3/4] nixos/slurm: add recommended mysql settings

---
 nixos/tests/slurm.nix | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/nixos/tests/slurm.nix b/nixos/tests/slurm.nix
index 7f9c266cbff6..30e408c7db1e 100644
--- a/nixos/tests/slurm.nix
+++ b/nixos/tests/slurm.nix
@@ -63,6 +63,12 @@ in {
             ensurePermissions = { "slurm_acct_db.*" = "ALL PRIVILEGES"; };
             name = "slurm";
           }];
+          extraOptions = ''
+            # recommendations from: https://slurm.schedmd.com/accounting.html#mysql-configuration
+            innodb_buffer_pool_size=1024M
+            innodb_log_file_size=64M
+            innodb_lock_wait_timeout=900
+          '';
         };
       };
 

From 8eee1ec2a9f0925bcf9589b330faacd0255ae700 Mon Sep 17 00:00:00 2001
From: Markus Kowalewski <markus.kowalewski@gmail.com>
Date: Sun, 9 Dec 2018 13:36:53 +0100
Subject: [PATCH 4/4] tests/slurm: wait for open DBD port

This makes tests more reliable. It seems
that waitForUnit(slurmdbd.service) is not sufficient
on some systems.
---
 nixos/tests/slurm.nix | 1 +
 1 file changed, 1 insertion(+)

diff --git a/nixos/tests/slurm.nix b/nixos/tests/slurm.nix
index 30e408c7db1e..b4458d8d0954 100644
--- a/nixos/tests/slurm.nix
+++ b/nixos/tests/slurm.nix
@@ -101,6 +101,7 @@ in {
   subtest "can_start_slurmdbd", sub {
     $dbd->succeed("systemctl restart slurmdbd");
     $dbd->waitForUnit("slurmdbd.service");
+    $dbd->waitForOpenPort(6819);
   };
 
   # there needs to be an entry for the current