scripts/update: implement -j option to control the number of parallel update jobs

This commit is contained in:
2025-03-15 04:45:28 +00:00
parent 855522daec
commit bbefa924cf

View File

@@ -2,6 +2,8 @@
#!nix-shell -i bash -p findutils -p nix-update
NIX_FILES_TOP=/home/colin/nixos
# each update job has to do an entire nix eval, which can be memory intensive; be careful when tuning this
PARALLELISM=8
usage() {
echo "update: update rev/hash for one or more packages"
@@ -10,6 +12,7 @@ usage() {
echo "options:"
echo "- --dry-run"
echo "- --verbose"
echo "- -j <n> (default: $PARALLELISM)"
echo ""
echo "examples:"
echo "- update nixpkgs: update only the nixpkgs input"
@@ -82,8 +85,8 @@ updateOnePkg() {
updatePkgsInParallel() {
debug "updating packages in parallel using xargs"
debug "- $@"
debug "- xargs -n 1 -P 4 $0 ${scriptFlags[*]}"
echo "$@" | xargs -n 1 -P 4 "$0" "${scriptFlags[@]}"
debug "- xargs -n 1 -P $PARALLELISM $0 ${scriptFlags[*]}"
echo "$@" | xargs -n 1 -P "$PARALLELISM" "$0" "${scriptFlags[@]}"
}
scriptFlags=()
@@ -107,6 +110,10 @@ parseArgs() {
scriptFlags+=(--verbose)
verbose=1
;;
(-j)
PARALLELISM=$1
shift
;;
(--*)
nixFlags+=("$arg")
;;