diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 6893d39382ea..ca28ecc81968 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -136,14 +136,20 @@ let '' # Create a writable qcow2 image using the systemImage as a backing # image. + BACKING_SIZE_MB=$(( $(${lib.getExe' qemu "qemu-img"} info ${systemImage}/nixos.qcow2 --output=json | ${lib.getExe hostPkgs.jq} -r '."virtual-size"') / 1024 / 1024 )) + DISK_SIZE_MB=${toString cfg.diskSize} + if (( DISK_SIZE_MB < BACKING_SIZE_MB )); then + OVERLAY_SIZE_MB=$BACKING_SIZE_MB + else + OVERLAY_SIZE_MB=$DISK_SIZE_MB + fi - # CoW prevent size to be attributed to an image. - # FIXME: raise this issue to upstream. ${qemu}/bin/qemu-img create \ -f qcow2 \ -b ${systemImage}/nixos.qcow2 \ -F qcow2 \ - "$NIX_DISK_IMAGE" + "$NIX_DISK_IMAGE" \ + ''${OVERLAY_SIZE_MB}M '' else if cfg.useDefaultFilesystems then ''