From 64dd9c1d6a6a7a9a89806b0e87d536483ba0a4f3 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 14 Jul 2020 08:10:38 -0400 Subject: [PATCH] stage-2: parameterized systemd executable This lets users do sneaky things before systemd starts, and permanently affect the environment in which systemd runs. For example, we could start systemd in a non-default network namespace by setting the systemdExecutable to a wrapper script containing: #!/bin/sh ip netns add virtual touch /var/run/netns/physical mount -o bind /proc/self/ns/net /var/run/netns/physical exec ip netns exec virtual systemd _note: the above example does literally work, but there are unresolved problems with udev and dhcp._ --- nixos/modules/system/boot/stage-2-init.sh | 2 +- nixos/modules/system/boot/stage-2.nix | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/nixos/modules/system/boot/stage-2-init.sh b/nixos/modules/system/boot/stage-2-init.sh index d1de7920df98..936077b9df1e 100644 --- a/nixos/modules/system/boot/stage-2-init.sh +++ b/nixos/modules/system/boot/stage-2-init.sh @@ -169,4 +169,4 @@ exec {logOutFd}>&- {logErrFd}>&- echo "starting systemd..." PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \ LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \ - exec systemd + exec @systemdExecutable@ diff --git a/nixos/modules/system/boot/stage-2.nix b/nixos/modules/system/boot/stage-2.nix index 6b0b47227301..dd6d83ee0094 100644 --- a/nixos/modules/system/boot/stage-2.nix +++ b/nixos/modules/system/boot/stage-2.nix @@ -10,6 +10,7 @@ let src = ./stage-2-init.sh; shellDebug = "${pkgs.bashInteractive}/bin/bash"; shell = "${pkgs.bash}/bin/bash"; + inherit (config.boot) systemdExecutable; isExecutable = true; inherit (config.nix) readOnlyStore; inherit useHostResolvConf; @@ -72,6 +73,15 @@ in ''; }; + systemdExecutable = mkOption { + default = "systemd"; + type = types.str; + description = '' + The program to execute to start systemd. Typically + systemd, which will find systemd in the + PATH. + ''; + }; }; };