systemd-initrd: Support secrets when boot loader doesn't

initrd-secrets: Fix service config with systemd-stage-1

Changed files
+5 -7
nixos
modules
system
boot
virtualisation
tests
initrd-network-openvpn
initrd-network-ssh
+2 -2
nixos/modules/system/boot/systemd/initrd-secrets.nix
···
# drop this service, we'd mount the /run tmpfs over the secret, making it
# invisible in stage 2.
script = ''
-
for secret in $(cd /.initrd-secrets; find . -type f); do
mkdir -p "$(dirname "/$secret")"
cp "/.initrd-secrets/$secret" "/$secret"
done
'';
-
unitConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
···
# drop this service, we'd mount the /run tmpfs over the secret, making it
# invisible in stage 2.
script = ''
+
for secret in $(cd /.initrd-secrets; find . -type f -o -type l); do
mkdir -p "$(dirname "/$secret")"
cp "/.initrd-secrets/$secret" "/$secret"
done
'';
+
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
+2
nixos/modules/virtualisation/qemu-vm.nix
···
boot.initrd.kernelModules = optionals (cfg.useNixStoreImage && !cfg.writableStore) [ "erofs" ];
boot.initrd.extraUtilsCommands = lib.mkIf (cfg.useDefaultFilesystems && !config.boot.initrd.systemd.enable)
''
# We need mke2fs in the initrd.
···
boot.initrd.kernelModules = optionals (cfg.useNixStoreImage && !cfg.writableStore) [ "erofs" ];
+
boot.loader.supportsInitrdSecrets = mkIf (!cfg.useBootLoader) (mkVMOverride false);
+
boot.initrd.extraUtilsCommands = lib.mkIf (cfg.useDefaultFilesystems && !config.boot.initrd.systemd.enable)
''
# We need mke2fs in the initrd.
+1 -1
nixos/tests/initrd-network-openvpn/default.nix
···
enable = true;
openvpn = {
enable = true;
-
configuration = "/dev/null";
};
};
};
···
enable = true;
openvpn = {
enable = true;
+
configuration = builtins.toFile "initrd.ovpn" "";
};
};
};
-4
nixos/tests/initrd-network-ssh/default.nix
···
hostKeys = [ ./ssh_host_ed25519_key ];
};
};
-
boot.initrd.extraUtilsCommands = ''
-
mkdir -p $out/secrets/etc/ssh
-
cat "${./ssh_host_ed25519_key}" > $out/secrets/etc/ssh/sh_host_ed25519_key
-
'';
boot.initrd.preLVMCommands = ''
while true; do
if [ -f fnord ]; then
···
hostKeys = [ ./ssh_host_ed25519_key ];
};
};
boot.initrd.preLVMCommands = ''
while true; do
if [ -f fnord ]; then