Switch to qcow2 in the interactive VM.

This commit is contained in:
zerox 2024-08-31 03:18:04 +05:00
parent 511388d837
commit 70a22d25a2
3 changed files with 8 additions and 6 deletions

View file

@ -30,6 +30,7 @@ let
disko.devices = cfg_.disko.devices;
};
testMode = true;
imageFormat = "qcow2";
};
rootDisk = {
name = "root";
@ -79,8 +80,8 @@ in
trap 'rm -rf "$tmp"' EXIT
${lib.concatMapStringsSep "\n" (disk: ''
${pkgs.qemu}/bin/qemu-img create -f qcow2 \
-b ${diskoImages}/${disk.name}.raw \
-F raw "$tmp"/${disk.name}.qcow2
-b ${diskoImages}/${disk.name}.qcow2 \
-F qcow2 "$tmp"/${disk.name}.qcow2
'') disks}
set +f
${vm}/bin/run-*-vm

View file

@ -8,6 +8,7 @@
, copyNixStore ? true
, testMode ? false
, extraConfig ? { }
, imageFormat ? "raw"
}:
let
vmTools = pkgs.vmTools.override {
@ -39,7 +40,7 @@ let
findutils
] ++ nixosConfig.config.disko.extraDependencies;
preVM = ''
${lib.concatMapStringsSep "\n" (disk: "truncate -s ${disk.imageSize} ${disk.name}.raw") (lib.attrValues nixosConfig.config.disko.devices.disk)}
${lib.concatMapStringsSep "\n" (disk: "${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} ${disk.name}.${imageFormat} ${disk.imageSize}") (lib.attrValues nixosConfig.config.disko.devices.disk)}
# This makes disko work, when canTouchEfiVariables is set to true.
# Technically these boot entries will no be persisted this way, but
# in most cases this is OK, because we can rely on the standard location for UEFI executables.
@ -48,7 +49,7 @@ let
postVM = ''
# shellcheck disable=SC2154
mkdir -p "$out"
${lib.concatMapStringsSep "\n" (disk: "mv ${disk.name}.raw \"$out\"/${disk.name}.raw") (lib.attrValues nixosConfig.config.disko.devices.disk)}
${lib.concatMapStringsSep "\n" (disk: "mv ${disk.name}.${imageFormat} \"$out\"/${disk.name}.${imageFormat}") (lib.attrValues nixosConfig.config.disko.devices.disk)}
${extraPostVM}
'';
@ -96,7 +97,7 @@ let
"-drive if=pflash,format=raw,unit=1,file=efivars.fd"
] ++ builtins.map
(disk:
"-drive file=${disk.name}.raw,if=virtio,cache=unsafe,werror=report,format=raw"
"-drive file=${disk.name}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}"
)
(lib.attrValues nixosConfig.config.disko.devices.disk));
in

View file

@ -20,7 +20,7 @@
type = lib.types.strMatching "[0-9]+[KMGTP]?";
description = ''
size of the image if the makeDiskImages function from diksoLib is used.
is used as an argument to truncate -s
is used as an argument to "qemu-img create ..."
'';
default = "2G";
};