nixos/qemu-vm: use CA certificates from host

Changed files
+36 -2
nixos
modules
profiles
security
virtualisation
+4
nixos/modules/profiles/macos-builder.nix
···
# This ensures that anything built on the guest isn't lost when the guest is
# restarted.
writableStoreUseTmpfs = false;
+
+
# Pass certificates from host to the guest otherwise when custom CA certificates
+
# are required we can't use the cached builder.
+
useHostCerts = true;
};
};
}
+5 -1
nixos/modules/security/ca.nix
···
{
options = {
+
security.pki.installCACerts = mkEnableOption "Add CA certificates to system" // {
+
default = true;
+
internal = true;
+
};
security.pki.certificateFiles = mkOption {
type = types.listOf types.path;
···
};
-
config = {
+
config = mkIf cfg.installCACerts {
# NixOS canonical location + Debian/Ubuntu/Arch/Gentoo compatibility.
environment.etc."ssl/certs/ca-certificates.crt".source = caBundle;
+27 -1
nixos/modules/virtualisation/qemu-vm.nix
···
# Create a directory for exchanging data with the VM.
mkdir -p "$TMPDIR/xchg"
+
${lib.optionalString cfg.useHostCerts
+
''
+
mkdir -p "$TMPDIR/certs"
+
if [ -e "$NIX_SSL_CERT_FILE" ]; then
+
cp -L "$NIX_SSL_CERT_FILE" "$TMPDIR"/certs/ca-certificates.crt
+
else
+
echo \$NIX_SSL_CERT_FILE should point to a valid file if virtualisation.useHostCerts is enabled.
+
fi
+
''}
+
${lib.optionalString cfg.useEFIBoot
''
# Expose EFI variables, it's useful even when we are not using a bootloader (!).
···
'';
};
-
virtualisation.bios =
mkOption {
type = types.nullOr types.package;
···
An alternate BIOS (such as `qboot`) with which to start the VM.
Should contain a file named `bios.bin`.
If `null`, QEMU's builtin SeaBIOS will be used.
+
'';
+
};
+
+
virtualisation.useHostCerts =
+
mkOption {
+
type = types.bool;
+
default = false;
+
description =
+
lib.mdDoc ''
+
If enabled, when `NIX_SSL_CERT_FILE` is set on the host,
+
pass the CA certificates from the host to the VM.
'';
};
···
source = ''"''${SHARED_DIR:-$TMPDIR/xchg}"'';
target = "/tmp/shared";
};
+
certs = mkIf cfg.useHostCerts {
+
source = ''"$TMPDIR"/certs'';
+
target = "/etc/ssl/certs";
+
};
};
+
+
security.pki.installCACerts = mkIf cfg.useHostCerts false;
virtualisation.qemu.networkingOptions =
let