From 59462da91769ff9d089a753a26ba77387349441d Mon Sep 17 00:00:00 2001 From: Nick Bathum Date: Fri, 24 Feb 2023 10:36:31 -0500 Subject: [PATCH 1/2] nixos/lib/make-disk-image: expose memSize parameter Generating large disk images can fail from out-of-memory in vm-run. --- doc/builders/images/makediskimage.section.md | 1 + nixos/lib/make-disk-image.nix | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/builders/images/makediskimage.section.md b/doc/builders/images/makediskimage.section.md index 833a6461e57b..c4566e753108 100644 --- a/doc/builders/images/makediskimage.section.md +++ b/doc/builders/images/makediskimage.section.md @@ -101,6 +101,7 @@ in diskSize = "auto"; additionalSpace = "0M"; # Defaults to 512M. copyChannel = false; + memSize = 2048; # Qemu VM memory size in megabytes. Defaults to 1024M. } ``` diff --git a/nixos/lib/make-disk-image.nix b/nixos/lib/make-disk-image.nix index 365fc1f03a5b..d641d1289fe4 100644 --- a/nixos/lib/make-disk-image.nix +++ b/nixos/lib/make-disk-image.nix @@ -154,6 +154,9 @@ To solve this, you can run `fdisk -l $image` and generate `dd if=$image of=$imag , # Shell code executed after the VM has finished. postVM ? "" +, # Guest memory size + memSize ? 1024 + , # Copy the contents of the Nix store to the root of the image and # skip further setup. Incompatible with `contents`, # `installBootLoader` and `configFile`. @@ -525,7 +528,7 @@ let format' = format; in let "-drive if=pflash,format=raw,unit=1,file=$efiVars" ] ); - memSize = 1024; + inherit memSize; } '' export PATH=${binPath}:$PATH From 519958c94bbe5dd9a9b34f529e0a8e56afc40df1 Mon Sep 17 00:00:00 2001 From: Nick Bathum Date: Sun, 26 Feb 2023 20:17:27 -0500 Subject: [PATCH 2/2] nixos/lib/make-multi-disk-zfs-image: expose memSize parameter closes #178095 --- nixos/lib/make-multi-disk-zfs-image.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/lib/make-multi-disk-zfs-image.nix b/nixos/lib/make-multi-disk-zfs-image.nix index f9046a485a7d..ecbde44971a9 100644 --- a/nixos/lib/make-multi-disk-zfs-image.nix +++ b/nixos/lib/make-multi-disk-zfs-image.nix @@ -73,6 +73,9 @@ , # Shell code executed after the VM has finished. postVM ? "" +, # Guest memory size + memSize ? 1024 + , name ? "nixos-disk-image" , # Disk image format, one of qcow2, qcow2-compressed, vdi, vpc, raw. @@ -242,6 +245,7 @@ let { QEMU_OPTS = "-drive file=$bootDiskImage,if=virtio,cache=unsafe,werror=report" + " -drive file=$rootDiskImage,if=virtio,cache=unsafe,werror=report"; + inherit memSize; preVM = '' PATH=$PATH:${pkgs.qemu_kvm}/bin mkdir $out