disko-images: add copyNixStoreThreads option for configurable parallelism

Allow users to override the automatic thread count detection for nix
store copying. The default "auto" behavior remains unchanged (min of
nproc and 8), but users can now specify a fixed thread count for
environments where the automatic detection isn't optimal.
This commit is contained in:
Jörg Thalheim
2025-12-09 08:59:57 +00:00
committed by Jörg Thalheim
parent 10cdd63203
commit 8e68aa819d
2 changed files with 22 additions and 1 deletions
+10 -1
View File
@@ -153,7 +153,16 @@ let
# systems, while -P 4 is ~30% slower. Cap at 8 but use fewer workers if the
# system has fewer cores.
mkdir -p ${systemToInstall.config.disko.rootMountPoint}/nix/store
P=$(nproc); [ "$P" -gt 8 ] && P=8
${
if cfg.copyNixStoreThreads == "auto" then
''
P=$(nproc); [ "$P" -gt 8 ] && P=8
''
else
''
P=${toString cfg.copyNixStoreThreads}
''
}
xargs -P "$P" -I {} cp --recursive {} ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${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 ""
+12
View File
@@ -106,6 +106,18 @@ in
default = true;
};
copyNixStoreThreads = lib.mkOption {
type = lib.types.either lib.types.ints.positive (lib.types.enum [ "auto" ]);
description = ''
Number of parallel threads to use when copying the nix store.
Set to "auto" (the default) to automatically determine based on CPU cores,
capped at 8. Higher values may hurt performance on some systems due to
virtiofsd file descriptor limits.
'';
default = "auto";
example = 4;
};
extraConfig = lib.mkOption {
description = ''
Extra NixOS config for your test. Can be used to specify a different luks key for tests.