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.

Changed files
+7 -5
nixos
modules
virtualisation
+7 -5
nixos/modules/virtualisation/lxc-container.nix
···
options = { };
-
config = {
boot.isContainer = true;
boot.postBootCommands =
''
···
contents = [
{
-
source = config.system.build.toplevel + "/init";
target = "/sbin/init";
}
# Technically this is not required for lxc, but having also make this configuration work with systemd-nspawn.
···
pseudoFiles = [
"/sbin d 0755 0 0"
-
"/sbin/init s 0555 0 0 ${config.system.build.toplevel}/init"
"/dev d 0755 0 0"
"/proc d 0555 0 0"
"/sys d 0555 0 0"
···
system.build.installBootLoader = pkgs.writeScript "install-lxd-sbin-init.sh" ''
#!${pkgs.runtimeShell}
-
${pkgs.coreutils}/bin/ln -fs "$1/init" /sbin/init
'';
# networkd depends on this, but systemd module disables this for containers
···
systemd.packages = [ pkgs.distrobuilder.generator ];
system.activationScripts.installInitScript = lib.mkForce ''
-
ln -fs $systemConfig/init /sbin/init
'';
};
}
···
options = { };
+
config = let
+
initScript = if config.boot.initrd.systemd.enable then "prepare-root" else "init";
+
in {
boot.isContainer = true;
boot.postBootCommands =
''
···
contents = [
{
+
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.
···
pseudoFiles = [
"/sbin d 0755 0 0"
+
"/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"
···
system.build.installBootLoader = pkgs.writeScript "install-lxd-sbin-init.sh" ''
#!${pkgs.runtimeShell}
+
${pkgs.coreutils}/bin/ln -fs "$1/${initScript}" /sbin/init
'';
# networkd depends on this, but systemd module disables this for containers
···
systemd.packages = [ pkgs.distrobuilder.generator ];
system.activationScripts.installInitScript = lib.mkForce ''
+
ln -fs $systemConfig/${initScript} /sbin/init
'';
};
}