Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 98894c8

Browse files
committedDec 5, 2024
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.
1 parent 785c1e0 commit 98894c8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
 

‎lib/make-disk-image.nix

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ let
4848
kmod
4949
] ++ cfg.extraDependencies;
5050
preVM = ''
51-
${lib.concatMapStringsSep "\n" (disk: "${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} ${disk.imageName}.${imageFormat} ${disk.imageSize}") (lib.attrValues diskoCfg.devices.disk)}
51+
# shellcheck disable=SC2154
52+
mkdir -p "$out"
53+
${lib.concatMapStringsSep "\n" (disk:
54+
# shellcheck disable=SC2154
55+
"${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} \"$out/${disk.imageName}.${imageFormat}\" ${disk.imageSize}"
56+
) (lib.attrValues diskoCfg.devices.disk)}
5257
# This makes disko work, when canTouchEfiVariables is set to true.
5358
# Technically these boot entries will no be persisted this way, but
5459
# in most cases this is OK, because we can rely on the standard location for UEFI executables.
5560
install -m600 ${pkgs.OVMF.variables} efivars.fd
5661
'';
57-
postVM = ''
58-
# shellcheck disable=SC2154
59-
mkdir -p "$out"
60-
${lib.concatMapStringsSep "\n" (disk: "mv ${disk.imageName}.${imageFormat} \"$out\"/${disk.imageName}.${imageFormat}") (lib.attrValues diskoCfg.devices.disk)}
61-
${cfg.extraPostVM}
62-
'';
6362

6463
closureInfo = pkgs.closureInfo {
6564
rootPaths = [ systemToInstall.config.system.build.toplevel ];
@@ -105,15 +104,16 @@ let
105104
"-drive if=pflash,format=raw,unit=1,file=efivars.fd"
106105
] ++ builtins.map
107106
(disk:
108-
"-drive file=${disk.imageName}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}"
107+
"-drive file=\"$out\"/${disk.imageName}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}"
109108
)
110109
(lib.attrValues diskoCfg.devices.disk));
111110
in
112111
{
113112
system.build.diskoImages = vmTools.runInLinuxVM (pkgs.runCommand cfg.name
114113
{
115114
buildInputs = dependencies;
116-
inherit preVM postVM QEMU_OPTS;
115+
inherit preVM QEMU_OPTS;
116+
postVm = cfg.extraPostVM;
117117
inherit (diskoCfg) memSize;
118118
}
119119
(partitioner + installer));
@@ -204,10 +204,13 @@ in
204204
echo "export origBuilder=$origBuilder" >> xchg/saved-env
205205
${preVM}
206206
''}
207-
export postVM=${diskoLib.writeCheckedBash { inherit pkgs checked; } "postVM.sh" postVM}
207+
export postVM=${diskoLib.writeCheckedBash { inherit pkgs checked; } "postVM.sh" cfg.extraPostVM}
208208
209209
build_memory=''${build_memory:-${builtins.toString diskoCfg.memSize}}
210+
# shellcheck disable=SC2016
210211
QEMU_OPTS=${lib.escapeShellArg QEMU_OPTS}
212+
# replace quoted $out with the actual path
213+
QEUM_OPTS=''${QEMU_OPTS//\$out/$out}
211214
QEMU_OPTS+=" -m $build_memory"
212215
export QEMU_OPTS
213216

0 commit comments

Comments
 (0)
Please sign in to comment.