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

View File

@ -5,8 +5,13 @@
It contains both the relevant guest settings as well as an installer script
that manages it as a QEMU virtual machine on the host.
*/
{ config, lib, options, ... }:
*/
{
config,
lib,
options,
...
}:
let
keysDirectory = "/var/keys";
@ -31,7 +36,10 @@ in
];
# swraid's default depends on stateVersion
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" (
''
set -euo pipefail
'' +
''
+
# When running as non-interactively as part of a DarwinConfiguration the working directory
# must be set to a writeable directory.
(if cfg.workingDirectory != "." then ''
(
if cfg.workingDirectory != "." then
''
${hostPkgs.coreutils}/bin/mkdir --parent "${cfg.workingDirectory}"
cd "${cfg.workingDirectory}"
'' else "") + ''
''
else
""
)
+ ''
KEYS="''${KEYS:-./keys}"
${hostPkgs.coreutils}/bin/mkdir --parent "''${KEYS}"
PRIVATE_KEY="''${KEYS}/${user}_${keyType}"
@ -179,7 +194,8 @@ in
(set -x; sudo --reset-timestamp ${installCredentials} "''${KEYS}")
fi
KEYS="$(${hostPkgs.nix}/bin/nix-store --add "$KEYS")" ${lib.getExe config.system.build.vm}
'');
''
);
in
script.overrideAttrs (old: {
@ -224,7 +240,11 @@ in
memorySize = cfg.memorySize;
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