From 70a22d25a2695caca52379aa94c514941fe687c3 Mon Sep 17 00:00:00 2001 From: zerox Date: Sat, 31 Aug 2024 03:18:04 +0500 Subject: [PATCH] Switch to qcow2 in the interactive VM. --- lib/interactive-vm.nix | 5 +++-- lib/make-disk-image.nix | 7 ++++--- lib/types/disk.nix | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/interactive-vm.nix b/lib/interactive-vm.nix index e37b321..6fb0098 100644 --- a/lib/interactive-vm.nix +++ b/lib/interactive-vm.nix @@ -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 diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index de9362b..8bcf03e 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -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 diff --git a/lib/types/disk.nix b/lib/types/disk.nix index 60f31b5..b240552 100644 --- a/lib/types/disk.nix +++ b/lib/types/disk.nix @@ -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"; };