4 # --print: avoid dependency on environment
6 if [ "$1" == "--print" ]; then
11 if [ "$#" != 1 ] && [ "$#" != 2 ]; then
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.
18 effect of latest commit:
21 effect of the whole patch series for 'staging' branch:
22 $ $0 origin/staging staging
27 # A slightly hacky way to get the config.
28 parallel
="$(echo 'config.rebuild-amount.parallel or false' | nix-repl . 2>/dev/null \
29 | grep -v '^\(nix-repl.*\)\?$' | tail -n 1 || true)"
31 echo "Estimating rebuild amount by counting changed Hydra jobs (parallel=${parallel:-unset})."
36 rm -rf "${toRemove[@]}"
40 MKTEMP
='mktemp --tmpdir nix-rebuild-amount-XXXXXXXX'
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 {};
51 recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };
53 # hydraJobs leaves recurseForDerivations as empty attrmaps;
54 # that would break nix-env and we also need to recurse everywhere.
57 if name == "recurseForDerivations" then true
58 else if lib.isAttrs val && val.type or null != "derivation"
59 then recurseIntoAttrs (tweak val)
63 # Some of these contain explicit references to platform(s) we want to avoid;
64 # some even (transitively) depend on ~/.nixpkgs/config.nix (!)
66 "tarball" "metrics" "manual"
67 "darwin-tested" "unstable" "stdenvBootstrapTools"
68 "moduleSystem" "lib-tests" # these just confuse the output
72 tweak (builtins.removeAttrs hydraJobs blacklist)
76 # Output packages in tree $2 that weren't in $1.
77 # Changing the output hash or name is taken as a change.
78 # Extra nix-env parameters can be in $3
80 # We use files instead of pipes, as running multiple nix-env processes
81 # could eat too much memory for a standard 4GiB machine.
92 nixexpr
"${!i}" > "$expr"
94 nix-env
-f "$expr" -qaP --no-name --out-path --show-trace $3 \
95 |
sort > "${list[$i]}" &
97 if [ "$parallel" != "true" ]; then
103 comm -13 "${list[@]}"
106 # Prepare nixpkgs trees.
109 if [ -n "${!i}" ]; then # use the given commit
114 git clone
--shared --no-checkout --quiet .
"${tree[$i]}"
115 (cd "${tree[$i]}" && git checkout
--quiet "${!i}")
116 else #use the current tree
122 toRemove
+=("$newlist")
124 # - the evaluation is done on x86_64-linux, like on Hydra.
125 # - using $newlist file so that newPkgs() isn't in a sub-shell (because of toRemove)
126 newPkgs
"${tree[1]}" "${tree[2]}" '--argstr system "x86_64-linux"' > "$newlist"
128 # Hacky: keep only the last word of each attribute path and sort.
129 sed -n 's/\([^. ]*\.\)*\([^. ]*\) .*$/\2/p' < "$newlist" \
132 if [ -n "$optPrint" ]; then