Skip to content

Instantly share code, notes, and snippets.

@vcunat
Created October 28, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcunat/b2eb3e8e8a916f1656ba4d1c7e5e4e32 to your computer and use it in GitHub Desktop.
Save vcunat/b2eb3e8e8a916f1656ba4d1c7e5e4e32 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ "$#" != 2 ]; then
echo "Usage: $0 commit-hash commit-hash"
echo -e "\tYou need to be in a git-controlled nixpkgs tree."
exit 1
fi
echo "Estimating rebuild amount, by packages visible to nix-env:"
echo "(If you get 0, it's an evaluation error, most likely.)"
# Output packages in tree $2 that weren't in $1.
# Changing the output hash or name is taken as a change.
# Extra nix-env parameters can be in $3
newPkgs() {
comm -13 \
<(nix-env -f "$1" -qa --out-path --show-trace $3 | sort) \
<(nix-env -f "$2" -qa --out-path --show-trace $3 | sort)
}
declare -a tree
for i in 1 2; do
tree[$i]="$(mktemp --tmpdir -d nix-rebuild-amount-XXXXXXXX)"
done
cleanup() {
rm -rf "${tree[1]}" "${tree[2]}"
}
trap cleanup EXIT SIGINT SIGQUIT ERR
for i in 1 2; do
git "--work-tree=${tree[$i]}" checkout "${!i}" "*"
done
for platform in x86_64-{linux,darwin}; do
newPkgs "${tree[1]}" "${tree[2]}" "--argstr system $platform" \
2>/dev/null \
| (wc -l; echo "^ $platform") &
done
wait
@vcunat
Copy link
Author

vcunat commented Oct 28, 2016

Bug: this is affected by your ~/.nixpkgs/config.nix; I could find no switch or variable allowing me to disable that.

@vcunat
Copy link
Author

vcunat commented Oct 29, 2016

Beware: the current implementation can change the git index. A better way to checkout files should be found (I didn't want a full clone).

@matthewbauer
Copy link

@vcunat You can set "config" as an arg to override ~/.nixpkgs/config.nix. For example:

nix-env -f "$2" -qa --out-path --show-trace $3 --arg config "{}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment