about summary refs log tree commit diff
path: root/nixos/modules/virtualisation/lxc-container.nix
diff options
context:
space:
mode:
authorMaciej Krüger <mkg20001@gmail.com>2024-02-20 23:12:41 +0100
committerMaciej Krüger <mkg20001@gmail.com>2024-02-20 23:12:41 +0100
commit39b4c0d686389c2a0eeb249b5c0d6ae1626b989b (patch)
treeef54ce3039bd7fee84564e95e633e30599b3d521 /nixos/modules/virtualisation/lxc-container.nix
parenteb60233fe87535d7236a42ea3f4c34b93c1b41d0 (diff)
nixos/lxc-container: link to prepare-root when boot.initrd.systemd.enable is on
Previously we were doing some parts like activation in the init script,
so linking to that works for non-systemd init

With boot.initrd.systemd.enable we no longer run activation in the init script,
but instead a new script named prepare-root, which is used instead.
Diffstat (limited to 'nixos/modules/virtualisation/lxc-container.nix')
-rw-r--r--nixos/modules/virtualisation/lxc-container.nix12
1 files changed, 7 insertions, 5 deletions
diff --git a/nixos/modules/virtualisation/lxc-container.nix b/nixos/modules/virtualisation/lxc-container.nix
index 8d3a480e6dc8c..95e3083ff9eda 100644
--- a/nixos/modules/virtualisation/lxc-container.nix
+++ b/nixos/modules/virtualisation/lxc-container.nix
@@ -14,7 +14,9 @@
 
   options = { };
 
-  config = {
+  config = let
+    initScript = if config.boot.initrd.systemd.enable then "prepare-root" else "init";
+  in {
     boot.isContainer = true;
     boot.postBootCommands =
       ''
@@ -41,7 +43,7 @@
 
       contents = [
         {
-          source = config.system.build.toplevel + "/init";
+          source = config.system.build.toplevel + "/${initScript}";
           target = "/sbin/init";
         }
         # Technically this is not required for lxc, but having also make this configuration work with systemd-nspawn.
@@ -65,7 +67,7 @@
 
       pseudoFiles = [
         "/sbin d 0755 0 0"
-        "/sbin/init s 0555 0 0 ${config.system.build.toplevel}/init"
+        "/sbin/init s 0555 0 0 ${config.system.build.toplevel}/${initScript}"
         "/dev d 0755 0 0"
         "/proc d 0555 0 0"
         "/sys d 0555 0 0"
@@ -74,7 +76,7 @@
 
     system.build.installBootLoader = pkgs.writeScript "install-lxd-sbin-init.sh" ''
       #!${pkgs.runtimeShell}
-      ${pkgs.coreutils}/bin/ln -fs "$1/init" /sbin/init
+      ${pkgs.coreutils}/bin/ln -fs "$1/${initScript}" /sbin/init
     '';
 
     # networkd depends on this, but systemd module disables this for containers
@@ -83,7 +85,7 @@
     systemd.packages = [ pkgs.distrobuilder.generator ];
 
     system.activationScripts.installInitScript = lib.mkForce ''
-      ln -fs $systemConfig/init /sbin/init
+      ln -fs $systemConfig/${initScript} /sbin/init
     '';
   };
 }