This commit is contained in:
Robert Hensing 2024-10-08 11:27:01 +02:00
parent 00355648f0
commit a034fb50f7

View File

@ -6,7 +6,12 @@
It contains both the relevant guest settings as well as an installer script It contains both the relevant guest settings as well as an installer script
that manages it as a QEMU virtual machine on the host. that manages it as a QEMU virtual machine on the host.
*/ */
{ config, lib, options, ... }: {
config,
lib,
options,
...
}:
let let
keysDirectory = "/var/keys"; keysDirectory = "/var/keys";
@ -31,7 +36,10 @@ in
]; ];
# swraid's default depends on stateVersion # swraid's default depends on stateVersion
config.boot.swraid.enable = false; config.boot.swraid.enable = false;
options.boot.isContainer = lib.mkOption { default = false; internal = true; }; options.boot.isContainer = lib.mkOption {
default = false;
internal = true;
};
} }
]; ];
@ -160,13 +168,20 @@ in
script = hostPkgs.writeShellScriptBin "create-builder" ( script = hostPkgs.writeShellScriptBin "create-builder" (
'' ''
set -euo pipefail set -euo pipefail
'' + ''
+
# When running as non-interactively as part of a DarwinConfiguration the working directory # When running as non-interactively as part of a DarwinConfiguration the working directory
# must be set to a writeable directory. # must be set to a writeable directory.
(if cfg.workingDirectory != "." then '' (
if cfg.workingDirectory != "." then
''
${hostPkgs.coreutils}/bin/mkdir --parent "${cfg.workingDirectory}" ${hostPkgs.coreutils}/bin/mkdir --parent "${cfg.workingDirectory}"
cd "${cfg.workingDirectory}" cd "${cfg.workingDirectory}"
'' else "") + '' ''
else
""
)
+ ''
KEYS="''${KEYS:-./keys}" KEYS="''${KEYS:-./keys}"
${hostPkgs.coreutils}/bin/mkdir --parent "''${KEYS}" ${hostPkgs.coreutils}/bin/mkdir --parent "''${KEYS}"
PRIVATE_KEY="''${KEYS}/${user}_${keyType}" PRIVATE_KEY="''${KEYS}/${user}_${keyType}"
@ -179,7 +194,8 @@ in
(set -x; sudo --reset-timestamp ${installCredentials} "''${KEYS}") (set -x; sudo --reset-timestamp ${installCredentials} "''${KEYS}")
fi fi
KEYS="$(${hostPkgs.nix}/bin/nix-store --add "$KEYS")" ${lib.getExe config.system.build.vm} KEYS="$(${hostPkgs.nix}/bin/nix-store --add "$KEYS")" ${lib.getExe config.system.build.vm}
''); ''
);
in in
script.overrideAttrs (old: { script.overrideAttrs (old: {
@ -224,7 +240,11 @@ in
memorySize = cfg.memorySize; memorySize = cfg.memorySize;
forwardPorts = [ forwardPorts = [
{ from = "host"; guest.port = 22; host.port = cfg.hostPort; } {
from = "host";
guest.port = 22;
host.port = cfg.hostPort;
}
]; ];
# Disable graphics for the builder since users will likely want to run it # Disable graphics for the builder since users will likely want to run it