git.iko.soy/typeable/nixpkgs
on master help sign in
maintainers/scripts/rebuild-amount.sh: report parallelism, add example, cleanup (#137695)

* maintainers/scripts/rebuild-amount.sh: report parallelism setting This slightly helps discovering parallelism support. * maintainers/scripts/rebuild-amount.sh: add basic example It's not clear if script should be used against HEAD or HEAD^. Let's have a copyable example. * maintainers/scripts/rebuild-amount.sh: convert tabs to four spaces One notable change is here-document conversion. Before: <TAB>cat <<-FOO <TAB>... <TAB>FOO After: <sp><sp><sp><sp>cat <<FOO <sp><sp><sp><sp>... FOO Note seemingly misaligned 'FOO': '-FOO' understands leading tabs, but not spaces.

commit39e8ec2db68b863543bd377e44fbe02f8d05864e authorSergei Trofimovich <slyich@gmail.com> dateFri 24 Sep 2021, 08:06 (5 years ago) parent1922e87
1 file changed+86−79
maintainers/scripts/rebuild-amount.sh+86−79
maintainers/scripts/rebuild-amount.sh+86−79
@@ -4,123 +4,130 @@ set -e
44# --print: avoid dependency on environment
55optPrint=
66if [ "$1" == "--print" ]; then
7− optPrint=true
8− shift
7+ optPrint=true
8+ shift
99fi
1010
1111if [ "$#" != 1 ] && [ "$#" != 2 ]; then
12− cat <<-EOF
13− Usage: $0 [--print] commit-spec [commit-spec]
14− You need to be in a git-controlled nixpkgs tree.
15− The current state of the tree will be used if the second commit is missing.
16− EOF
17− exit 1
12+ cat <<EOF
13+ Usage: $0 [--print] from-commit-spec [to-commit-spec]
14+ You need to be in a git-controlled nixpkgs tree.
15+ The current state of the tree will be used if the second commit is missing.
16+
17+ Examples:
18+ effect of latest commit:
19+ $ $0 HEAD^
20+ $ $0 --print HEAD^
21+ effect of the whole patch series for 'staging' branch:
22+ $ $0 origin/staging staging
23+EOF
24+ exit 1
1825fi
1926
2027# A slightly hacky way to get the config.
2128parallel="$(echo 'config.rebuild-amount.parallel or false' | nix-repl . 2>/dev/null \
22− | grep -v '^\(nix-repl.*\)\?$' | tail -n 1 || true)"
29+ | grep -v '^\(nix-repl.*\)\?$' | tail -n 1 || true)"
2330
24−echo "Estimating rebuild amount by counting changed Hydra jobs."
31+echo "Estimating rebuild amount by counting changed Hydra jobs (parallel=${parallel:-unset})."
2532
2633toRemove=()
2734
2835cleanup() {
29− rm -rf "${toRemove[@]}"
36+ rm -rf "${toRemove[@]}"
3037}
3138trap cleanup EXIT SIGINT SIGQUIT ERR
3239
3340MKTEMP='mktemp --tmpdir nix-rebuild-amount-XXXXXXXX'
3441
3542nixexpr() {
36− cat <<-EONIX
37− let
38− lib = import $1/lib;
39− hydraJobs = import $1/pkgs/top-level/release.nix
40− # Compromise: accuracy vs. resources needed for evaluation.
41− { supportedSystems = cfg.systems or [ "x86_64-linux" "x86_64-darwin" ]; };
42− cfg = (import $1 {}).config.rebuild-amount or {};
43−
44− recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };
45−
46− # hydraJobs leaves recurseForDerivations as empty attrmaps;
47− # that would break nix-env and we also need to recurse everywhere.
48− tweak = lib.mapAttrs
49− (name: val:
50− if name == "recurseForDerivations" then true
51− else if lib.isAttrs val && val.type or null != "derivation"
52− then recurseIntoAttrs (tweak val)
53− else val
54− );
55−
56− # Some of these contain explicit references to platform(s) we want to avoid;
57− # some even (transitively) depend on ~/.nixpkgs/config.nix (!)
58− blacklist = [
59− "tarball" "metrics" "manual"
60− "darwin-tested" "unstable" "stdenvBootstrapTools"
61− "moduleSystem" "lib-tests" # these just confuse the output
62− ];
63−
64− in
65− tweak (builtins.removeAttrs hydraJobs blacklist)
66− EONIX
43+ cat <<EONIX
44+ let
45+ lib = import $1/lib;
46+ hydraJobs = import $1/pkgs/top-level/release.nix
47+ # Compromise: accuracy vs. resources needed for evaluation.
48+ { supportedSystems = cfg.systems or [ "x86_64-linux" "x86_64-darwin" ]; };
49+ cfg = (import $1 {}).config.rebuild-amount or {};
50+
51+ recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };
52+
53+ # hydraJobs leaves recurseForDerivations as empty attrmaps;
54+ # that would break nix-env and we also need to recurse everywhere.
55+ tweak = lib.mapAttrs
56+ (name: val:
57+ if name == "recurseForDerivations" then true
58+ else if lib.isAttrs val && val.type or null != "derivation"
59+ then recurseIntoAttrs (tweak val)
60+ else val
61+ );
62+
63+ # Some of these contain explicit references to platform(s) we want to avoid;
64+ # some even (transitively) depend on ~/.nixpkgs/config.nix (!)
65+ blacklist = [
66+ "tarball" "metrics" "manual"
67+ "darwin-tested" "unstable" "stdenvBootstrapTools"
68+ "moduleSystem" "lib-tests" # these just confuse the output
69+ ];
70+
71+ in
72+ tweak (builtins.removeAttrs hydraJobs blacklist)
73+EONIX
6774}
6875
6976# Output packages in tree $2 that weren't in $1.
7077# Changing the output hash or name is taken as a change.
7178# Extra nix-env parameters can be in $3
7279newPkgs() {
73− # We use files instead of pipes, as running multiple nix-env processes
74− # could eat too much memory for a standard 4GiB machine.
75− local -a list
76− for i in 1 2; do
77− local l="$($MKTEMP)"
78− list[$i]="$l"
79− toRemove+=("$l")
80−
81− local expr="$($MKTEMP)"
82− toRemove+=("$expr")
83− nixexpr "${!i}" > "$expr"
84−
85− nix-env -f "$expr" -qaP --no-name --out-path --show-trace $3 \
86− | sort > "${list[$i]}" &
87−
88− if [ "$parallel" != "true" ]; then
89− wait
90− fi
91− done
92−
93− wait
94− comm -13 "${list[@]}"
80+ # We use files instead of pipes, as running multiple nix-env processes
81+ # could eat too much memory for a standard 4GiB machine.
82+ local -a list
83+ for i in 1 2; do
84+ local l="$($MKTEMP)"
85+ list[$i]="$l"
86+ toRemove+=("$l")
87+
88+ local expr="$($MKTEMP)"
89+ toRemove+=("$expr")
90+ nixexpr "${!i}" > "$expr"
91+
92+ nix-env -f "$expr" -qaP --no-name --out-path --show-trace $3 \
93+ | sort > "${list[$i]}" &
94+
95+ if [ "$parallel" != "true" ]; then
96+ wait
97+ fi
98+ done
99+
100+ wait
101+ comm -13 "${list[@]}"
95102}
96103
97104# Prepare nixpkgs trees.
98105declare -a tree
99106for i in 1 2; do
100− if [ -n "${!i}" ]; then # use the given commit
101− dir="$($MKTEMP -d)"
102− tree[$i]="$dir"
103− toRemove+=("$dir")
104−
105− git clone --shared --no-checkout --quiet . "${tree[$i]}"
106− (cd "${tree[$i]}" && git checkout --quiet "${!i}")
107− else #use the current tree
108− tree[$i]="$(pwd)"
109− fi
107+ if [ -n "${!i}" ]; then # use the given commit
108+ dir="$($MKTEMP -d)"
109+ tree[$i]="$dir"
110+ toRemove+=("$dir")
111+
112+ git clone --shared --no-checkout --quiet . "${tree[$i]}"
113+ (cd "${tree[$i]}" && git checkout --quiet "${!i}")
114+ else #use the current tree
115+ tree[$i]="$(pwd)"
116+ fi
110117done
111118
112119newlist="$($MKTEMP)"
113120toRemove+=("$newlist")
114121# Notes:
115−# - the evaluation is done on x86_64-linux, like on Hydra.
116−# - using $newlist file so that newPkgs() isn't in a sub-shell (because of toRemove)
122+# - the evaluation is done on x86_64-linux, like on Hydra.
123+# - using $newlist file so that newPkgs() isn't in a sub-shell (because of toRemove)
117124newPkgs "${tree[1]}" "${tree[2]}" '--argstr system "x86_64-linux"' > "$newlist"
118125
119126# Hacky: keep only the last word of each attribute path and sort.
120127sed -n 's/\([^. ]*\.\)*\([^. ]*\) .*$/\2/p' < "$newlist" \
121− | sort | uniq -c
128+ | sort | uniq -c
122129
123130if [ -n "$optPrint" ]; then
124− echo
125− cat "$newlist"
131+ echo
132+ cat "$newlist"
126133fi