From 8e68aa819d6a9964c8ac45172e68b943b597c52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 9 Dec 2025 09:26:57 +0100 Subject: [PATCH] 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. --- lib/make-disk-image.nix | 11 ++++++++++- module.nix | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index 8c3d550..2e1b55f 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -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 "" diff --git a/module.nix b/module.nix index 421efcf..1094a5c 100644 --- a/module.nix +++ b/module.nix @@ -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.