diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index be491f7b..409bd046 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 cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${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 {