make-disk-image: add compressed option to compress qcow2 images
This commit is contained in:
parent
a2d3ee77b8
commit
608de48fe4
@ -35,11 +35,16 @@
|
|||||||
|
|
||||||
, # Disk image format, one of qcow2, vpc, raw.
|
, # Disk image format, one of qcow2, vpc, raw.
|
||||||
format ? "raw"
|
format ? "raw"
|
||||||
|
|
||||||
|
, # Whether to compress the image, applicable only when the format is qcow2.
|
||||||
|
compressed ? false
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
compress = optionalString compressed (assert format == "qcow2"; "-c");
|
||||||
|
|
||||||
filename = "nixos." + {
|
filename = "nixos." + {
|
||||||
qcow2 = "qcow2";
|
qcow2 = "qcow2";
|
||||||
vpc = "vhd";
|
vpc = "vhd";
|
||||||
@ -136,7 +141,7 @@ in pkgs.vmTools.runInLinuxVM (
|
|||||||
${if format == "raw" then ''
|
${if format == "raw" then ''
|
||||||
mv $diskImage $out/${filename}
|
mv $diskImage $out/${filename}
|
||||||
'' else ''
|
'' else ''
|
||||||
${pkgs.qemu}/bin/qemu-img convert -f raw -O ${format} $diskImage $out/${filename}
|
${pkgs.qemu}/bin/qemu-img convert -f raw -O ${format} ${compress} $diskImage $out/${filename}
|
||||||
''}
|
''}
|
||||||
diskImage=$out/${filename}
|
diskImage=$out/${filename}
|
||||||
${postVM}
|
${postVM}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user