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._
This commit is contained in:
Graham Christensen 2020-07-14 08:10:38 -04:00
parent 1facbd61b1
commit 64dd9c1d6a
No known key found for this signature in database
GPG key ID: FE918C3A98C1030F
2 changed files with 11 additions and 1 deletions

View file

@ -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@

View file

@ -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
<literal>systemd</literal>, which will find systemd in the
PATH.
'';
};
};
};