summary refs log tree commit diff
path: root/nixos/lib
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/lib
parent4d60081494259c0785f7e228518fee74e0792c1b (diff)
downloadnixpkgs-c70a466d21fbd72f73cfc263e93f967e79953e73.tar
nixpkgs-c70a466d21fbd72f73cfc263e93f967e79953e73.tar.gz
nixpkgs-c70a466d21fbd72f73cfc263e93f967e79953e73.tar.bz2
nixpkgs-c70a466d21fbd72f73cfc263e93f967e79953e73.tar.lz
nixpkgs-c70a466d21fbd72f73cfc263e93f967e79953e73.tar.xz
nixpkgs-c70a466d21fbd72f73cfc263e93f967e79953e73.tar.zst
nixpkgs-c70a466d21fbd72f73cfc263e93f967e79953e73.zip
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/lib')
-rw-r--r--nixos/lib/systemd-lib.nix10
1 files changed, 6 insertions, 4 deletions
diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix
index a472d97f5cc..37900b0b16f 100644
--- a/nixos/lib/systemd-lib.nix
+++ b/nixos/lib/systemd-lib.nix
@@ -23,8 +23,9 @@ in rec {
           inherit (unit) text;
         }
         ''
-          mkdir -p $out
-          echo -n "$text" > $out/${shellEscape name}
+          name=${shellEscape name}
+          mkdir -p "$out/$(dirname "$name")"
+          echo -n "$text" > "$out/$name"
         ''
     else
       pkgs.runCommand "unit-${mkPathSafeName name}-disabled"
@@ -32,8 +33,9 @@ in rec {
           allowSubstitutes = false;
         }
         ''
-          mkdir -p $out
-          ln -s /dev/null $out/${shellEscape name}
+          name=${shellEscape name}
+          mkdir -p "$out/$(dirname "$name")"
+          ln -s /dev/null "$out/$name"
         '';
 
   boolValues = [true false "yes" "no"];