From 603813ee37b9a1298208fe37eab5f0b919b2d6e4 Mon Sep 17 00:00:00 2001 From: danjujan <44864658+danjujan@users.noreply.github.com> Date: Wed, 4 Dec 2024 20:41:42 +0100 Subject: [PATCH 1/3] make-disk-image: improve xargs invocation --- lib/make-disk-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index be491f7b..367eae4f 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -94,7 +94,7 @@ let # We copy files with cp because `nix copy` seems to have a large memory leak mkdir -p ${systemToInstall.config.disko.rootMountPoint}/nix/store - xargs cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${closureInfo}/store-paths + xargs -P 0 -I {} sh -c 'cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store "$1" || exit 255' sh {} < ${closureInfo}/store-paths ${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root ${systemToInstall.config.disko.rootMountPoint} --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches "" umount -Rv ${systemToInstall.config.disko.rootMountPoint} From e6c2ca8c24a1a30ef24e5856436360a1db84a197 Mon Sep 17 00:00:00 2001 From: danjujan <44864658+danjujan@users.noreply.github.com> Date: Thu, 5 Dec 2024 18:32:18 +0100 Subject: [PATCH 2/3] make-disk-image: save xargs invocation overhead --- lib/make-disk-image.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index 367eae4f..313ce16f 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -87,14 +87,21 @@ let ${lib.getExe systemToInstall.config.system.build.destroyFormatMount} --yes-wipe-all-disks ''; - installer = lib.optionalString cfg.copyNixStore '' + installer = + let + # let xargs stop directly when cp fails + cpEarlyExit = pkgs.writeScript "cp-early-exit" '' + cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store "$@" || exit 255 + ''; + in + lib.optionalString cfg.copyNixStore '' # populate nix db, so nixos-install doesn't complain export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix nix-store --load-db < "${closureInfo}/registration" # We copy files with cp because `nix copy` seems to have a large memory leak mkdir -p ${systemToInstall.config.disko.rootMountPoint}/nix/store - xargs -P 0 -I {} sh -c 'cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store "$1" || exit 255' sh {} < ${closureInfo}/store-paths + xargs -P 0 ${cpEarlyExit} < ${closureInfo}/store-paths ${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root ${systemToInstall.config.disko.rootMountPoint} --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches "" umount -Rv ${systemToInstall.config.disko.rootMountPoint} From 472e4d537c7591f184e904af1e67d0f6eeae7531 Mon Sep 17 00:00:00 2001 From: danjujan <44864658+danjujan@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:17:25 +0100 Subject: [PATCH 3/3] make-disk-image: make xargs flags configurable --- lib/make-disk-image.nix | 2 +- module.nix | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index 313ce16f..409bd046 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -101,7 +101,7 @@ let # We copy files with cp because `nix copy` seems to have a large memory leak mkdir -p ${systemToInstall.config.disko.rootMountPoint}/nix/store - xargs -P 0 ${cpEarlyExit} < ${closureInfo}/store-paths + xargs ${cfg.xargsFlags} ${cpEarlyExit} < ${closureInfo}/store-paths ${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root ${systemToInstall.config.disko.rootMountPoint} --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches "" umount -Rv ${systemToInstall.config.disko.rootMountPoint} diff --git a/module.nix b/module.nix index 6543e111..3f213c3c 100644 --- a/module.nix +++ b/module.nix @@ -102,6 +102,13 @@ in description = "QEMU image format to use for the disk images"; default = "raw"; }; + + xargsFlags = lib.mkOption { + type = lib.types.str; + description = "flags for xargs invocation"; + default = ""; + example = "-L 100 -P 0"; + }; }; memSize = lib.mkOption {