about summary refs log tree commit diff
path: root/nixos/tests/systemd-misc.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2021-08-11 20:28:30 +0200
committerSilvan Mosberger <contact@infinisil.com>2022-03-25 17:47:44 +0100
commitc70a466d21fbd72f73cfc263e93f967e79953e73 (patch)
treeb433402ef91dd0d296ce50f01448e24e9b8575de /nixos/tests/systemd-misc.nix
parent4d60081494259c0785f7e228518fee74e0792c1b (diff)
nixos/systemd: Allow creation of unit directories
This patch allows creation of files like
/etc/systemd/system/user-.slice.d/limits.conf with

    systemd.units."user-.slice.d/limits.conf" = {
      text = ''
        [Slice]
        CPUAccounting=yes
        CPUQuota=50%
      '';
    };

which previously threw an error

Also renames the systemd-unit-path test to sytsemd-misc, and extends it to
test that `systemd.units` can handle directories. In this case we make
sure that resource limits specified in user slices apply.
Diffstat (limited to 'nixos/tests/systemd-misc.nix')
-rw-r--r--nixos/tests/systemd-misc.nix62
1 files changed, 62 insertions, 0 deletions
diff --git a/nixos/tests/systemd-misc.nix b/nixos/tests/systemd-misc.nix
new file mode 100644
index 0000000000000..e416baa8b5f56
--- /dev/null
+++ b/nixos/tests/systemd-misc.nix
@@ -0,0 +1,62 @@
+import ./make-test-python.nix ({ pkgs, ... }:
+
+let
+  exampleScript = pkgs.writeTextFile {
+    name = "example.sh";
+    text = ''
+      #! ${pkgs.runtimeShell} -e
+
+      while true; do
+          echo "Example script running" >&2
+          ${pkgs.coreutils}/bin/sleep 1
+      done
+    '';
+    executable = true;
+  };
+
+  unitFile = pkgs.writeTextFile {
+    name = "example.service";
+    text = ''
+      [Unit]
+      Description=Example systemd service unit file
+
+      [Service]
+      ExecStart=${exampleScript}
+
+      [Install]
+      WantedBy=multi-user.target
+    '';
+  };
+in
+{
+  name = "systemd-misc";
+
+  machine = { pkgs, lib, ... }: {
+    boot.extraSystemdUnitPaths = [ "/etc/systemd-rw/system" ];
+
+    users.users.limited = {
+      isNormalUser = true;
+      uid = 1000;
+    };
+
+    systemd.units."user-1000.slice.d/limits.conf" = {
+      text = ''
+        [Slice]
+        TasksAccounting=yes
+        TasksMax=100
+      '';
+    };
+  };
+
+  testScript = ''
+    machine.wait_for_unit("multi-user.target")
+    machine.succeed("mkdir -p /etc/systemd-rw/system")
+    machine.succeed(
+        "cp ${unitFile} /etc/systemd-rw/system/example.service"
+    )
+    machine.succeed("systemctl start example.service")
+    machine.succeed("systemctl status example.service | grep 'Active: active'")
+
+    machine.succeed("systemctl show --property TasksMax --value user-1000.slice | grep 100")
+  '';
+})