···234234 # This ensures that anything built on the guest isn't lost when the guest is
235235 # restarted.
236236 writableStoreUseTmpfs = false;
237237+238238+ # Pass certificates from host to the guest otherwise when custom CA certificates
239239+ # are required we can't use the cached builder.
240240+ useHostCerts = true;
237241 };
238242 };
239243}
···166166 # Create a directory for exchanging data with the VM.
167167 mkdir -p "$TMPDIR/xchg"
168168169169+ ${lib.optionalString cfg.useHostCerts
170170+ ''
171171+ mkdir -p "$TMPDIR/certs"
172172+ if [ -e "$NIX_SSL_CERT_FILE" ]; then
173173+ cp -L "$NIX_SSL_CERT_FILE" "$TMPDIR"/certs/ca-certificates.crt
174174+ else
175175+ echo \$NIX_SSL_CERT_FILE should point to a valid file if virtualisation.useHostCerts is enabled.
176176+ fi
177177+ ''}
178178+169179 ${lib.optionalString cfg.useEFIBoot
170180 ''
171181 # Expose EFI variables, it's useful even when we are not using a bootloader (!).
···877887 '';
878888 };
879889880880-881890 virtualisation.bios =
882891 mkOption {
883892 type = types.nullOr types.package;
···887896 An alternate BIOS (such as `qboot`) with which to start the VM.
888897 Should contain a file named `bios.bin`.
889898 If `null`, QEMU's builtin SeaBIOS will be used.
899899+ '';
900900+ };
901901+902902+ virtualisation.useHostCerts =
903903+ mkOption {
904904+ type = types.bool;
905905+ default = false;
906906+ description =
907907+ lib.mdDoc ''
908908+ If enabled, when `NIX_SSL_CERT_FILE` is set on the host,
909909+ pass the CA certificates from the host to the VM.
890910 '';
891911 };
892912···10241044 source = ''"''${SHARED_DIR:-$TMPDIR/xchg}"'';
10251045 target = "/tmp/shared";
10261046 };
10471047+ certs = mkIf cfg.useHostCerts {
10481048+ source = ''"$TMPDIR"/certs'';
10491049+ target = "/etc/ssl/certs";
10501050+ };
10271051 };
10521052+10531053+ security.pki.installCACerts = mkIf cfg.useHostCerts false;
1028105410291055 virtualisation.qemu.networkingOptions =
10301056 let