summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJakub Okoński <jakub@okonski.org>2022-10-29 22:22:57 +0200
committerJakub Okoński <jakub@okonski.org>2022-11-06 17:12:02 +0100
commit12508ac79a3b940d42580e9cfb7d2037e7af3b00 (patch)
tree5d15998a7a2d4ad0f248aa35de8b9a431ce4689e /nixos
parentb0bce6ae731d5be0aed3277eab29d7ae7491d08d (diff)
downloadnixpkgs-12508ac79a3b940d42580e9cfb7d2037e7af3b00.tar
nixpkgs-12508ac79a3b940d42580e9cfb7d2037e7af3b00.tar.gz
nixpkgs-12508ac79a3b940d42580e9cfb7d2037e7af3b00.tar.bz2
nixpkgs-12508ac79a3b940d42580e9cfb7d2037e7af3b00.tar.lz
nixpkgs-12508ac79a3b940d42580e9cfb7d2037e7af3b00.tar.xz
nixpkgs-12508ac79a3b940d42580e9cfb7d2037e7af3b00.tar.zst
nixpkgs-12508ac79a3b940d42580e9cfb7d2037e7af3b00.zip
nixos-container: force systemd-nspawn to use unified cgroups hierarchy
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/virtualisation/nixos-containers.nix2
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/containers-unified-hierarchy.nix21
3 files changed, 24 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix
index 22be1d5bff9..4d51c53a604 100644
--- a/nixos/modules/virtualisation/nixos-containers.nix
+++ b/nixos/modules/virtualisation/nixos-containers.nix
@@ -138,6 +138,8 @@ let
         fi
       ''}
 
+      export SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=1
+
       # Run systemd-nspawn without startup notification (we'll
       # wait for the container systemd to signal readiness)
       # Kill signal handling means systemd-nspawn will pass a system-halt signal
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 47a433c0322..fe75f158290 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -143,6 +143,7 @@ in {
   containers-reloadable = handleTest ./containers-reloadable.nix {};
   containers-restart_networking = handleTest ./containers-restart_networking.nix {};
   containers-tmpfs = handleTest ./containers-tmpfs.nix {};
+  containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix {};
   convos = handleTest ./convos.nix {};
   corerad = handleTest ./corerad.nix {};
   coturn = handleTest ./coturn.nix {};
diff --git a/nixos/tests/containers-unified-hierarchy.nix b/nixos/tests/containers-unified-hierarchy.nix
new file mode 100644
index 00000000000..978d59e12c8
--- /dev/null
+++ b/nixos/tests/containers-unified-hierarchy.nix
@@ -0,0 +1,21 @@
+import ./make-test-python.nix ({ pkgs, lib, ... }: {
+  name = "containers-unified-hierarchy";
+  meta = {
+    maintainers = with lib.maintainers; [ farnoy ];
+  };
+
+  nodes.machine = { ... }: {
+    containers = {
+      test-container = {
+        autoStart = true;
+        config = { };
+      };
+    };
+  };
+
+  testScript = ''
+    machine.wait_for_unit("default.target")
+
+    machine.succeed("echo 'stat -fc %T /sys/fs/cgroup/ | grep cgroup2fs' | nixos-container root-login test-container")
+  '';
+})