mirror of
https://github.com/nix-community/disko.git
synced 2026-12-04 06:53:28 +01:00
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.
This commit is contained in:
1 parent
785c1e02c7
commit
98894c8598
1 file changed
+13
-10
+13
-10
@@ -48,18 +48,17 @@ let
|
|||||||
kmod
|
kmod
|
||||||
] ++ cfg.extraDependencies;
|
] ++ cfg.extraDependencies;
|
||||||
preVM = ''
|
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.
|
# This makes disko work, when canTouchEfiVariables is set to true.
|
||||||
# Technically these boot entries will no be persisted this way, but
|
# 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.
|
# in most cases this is OK, because we can rely on the standard location for UEFI executables.
|
||||||
install -m600 ${pkgs.OVMF.variables} efivars.fd
|
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 {
|
closureInfo = pkgs.closureInfo {
|
||||||
rootPaths = [ systemToInstall.config.system.build.toplevel ];
|
rootPaths = [ systemToInstall.config.system.build.toplevel ];
|
||||||
@@ -105,7 +104,7 @@ let
|
|||||||
"-drive if=pflash,format=raw,unit=1,file=efivars.fd"
|
"-drive if=pflash,format=raw,unit=1,file=efivars.fd"
|
||||||
] ++ builtins.map
|
] ++ builtins.map
|
||||||
(disk:
|
(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));
|
(lib.attrValues diskoCfg.devices.disk));
|
||||||
in
|
in
|
||||||
@@ -113,7 +112,8 @@ in
|
|||||||
system.build.diskoImages = vmTools.runInLinuxVM (pkgs.runCommand cfg.name
|
system.build.diskoImages = vmTools.runInLinuxVM (pkgs.runCommand cfg.name
|
||||||
{
|
{
|
||||||
buildInputs = dependencies;
|
buildInputs = dependencies;
|
||||||
inherit preVM postVM QEMU_OPTS;
|
inherit preVM QEMU_OPTS;
|
||||||
|
postVm = cfg.extraPostVM;
|
||||||
inherit (diskoCfg) memSize;
|
inherit (diskoCfg) memSize;
|
||||||
}
|
}
|
||||||
(partitioner + installer));
|
(partitioner + installer));
|
||||||
@@ -204,10 +204,13 @@ in
|
|||||||
echo "export origBuilder=$origBuilder" >> xchg/saved-env
|
echo "export origBuilder=$origBuilder" >> xchg/saved-env
|
||||||
${preVM}
|
${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}}
|
build_memory=''${build_memory:-${builtins.toString diskoCfg.memSize}}
|
||||||
|
# shellcheck disable=SC2016
|
||||||
QEMU_OPTS=${lib.escapeShellArg QEMU_OPTS}
|
QEMU_OPTS=${lib.escapeShellArg QEMU_OPTS}
|
||||||
|
# replace quoted $out with the actual path
|
||||||
|
QEUM_OPTS=''${QEMU_OPTS//\$out/$out}
|
||||||
QEMU_OPTS+=" -m $build_memory"
|
QEMU_OPTS+=" -m $build_memory"
|
||||||
export QEMU_OPTS
|
export QEMU_OPTS
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user