From 98894c85988a54e828a06db984aace21c718a0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 5 Dec 2024 08:12:23 +0100 Subject: [PATCH] make-disk-image: create directories images in out path In case we are crossing some filesystem boundary (i.e. /tmp -> /nix/store), this is faster. Also tmpfs might be probelemantic regarding memory usage. --- lib/make-disk-image.nix | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index be491f7..748aa62 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -48,18 +48,17 @@ let kmod ] ++ cfg.extraDependencies; preVM = '' - ${lib.concatMapStringsSep "\n" (disk: "${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} ${disk.imageName}.${imageFormat} ${disk.imageSize}") (lib.attrValues diskoCfg.devices.disk)} + # shellcheck disable=SC2154 + mkdir -p "$out" + ${lib.concatMapStringsSep "\n" (disk: + # shellcheck disable=SC2154 + "${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} \"$out/${disk.imageName}.${imageFormat}\" ${disk.imageSize}" + ) (lib.attrValues diskoCfg.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. install -m600 ${pkgs.OVMF.variables} efivars.fd ''; - postVM = '' - # shellcheck disable=SC2154 - mkdir -p "$out" - ${lib.concatMapStringsSep "\n" (disk: "mv ${disk.imageName}.${imageFormat} \"$out\"/${disk.imageName}.${imageFormat}") (lib.attrValues diskoCfg.devices.disk)} - ${cfg.extraPostVM} - ''; closureInfo = pkgs.closureInfo { rootPaths = [ systemToInstall.config.system.build.toplevel ]; @@ -105,7 +104,7 @@ let "-drive if=pflash,format=raw,unit=1,file=efivars.fd" ] ++ builtins.map (disk: - "-drive file=${disk.imageName}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}" + "-drive file=\"$out\"/${disk.imageName}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}" ) (lib.attrValues diskoCfg.devices.disk)); in @@ -113,7 +112,8 @@ in system.build.diskoImages = vmTools.runInLinuxVM (pkgs.runCommand cfg.name { buildInputs = dependencies; - inherit preVM postVM QEMU_OPTS; + inherit preVM QEMU_OPTS; + postVm = cfg.extraPostVM; inherit (diskoCfg) memSize; } (partitioner + installer)); @@ -204,10 +204,13 @@ in echo "export origBuilder=$origBuilder" >> xchg/saved-env ${preVM} ''} - export postVM=${diskoLib.writeCheckedBash { inherit pkgs checked; } "postVM.sh" postVM} + export postVM=${diskoLib.writeCheckedBash { inherit pkgs checked; } "postVM.sh" cfg.extraPostVM} build_memory=''${build_memory:-${builtins.toString diskoCfg.memSize}} + # shellcheck disable=SC2016 QEMU_OPTS=${lib.escapeShellArg QEMU_OPTS} + # replace quoted $out with the actual path + QEUM_OPTS=''${QEMU_OPTS//\$out/$out} QEMU_OPTS+=" -m $build_memory" export QEMU_OPTS