summaryrefslogtreecommitdiffstats
path: root/nix-script-channel-diff-generations.sh
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2015-05-28 21:52:43 +0200
committerMatthias Beyer <mail@beyermatthias.de>2015-09-07 16:11:45 +0200
commitbd75f32309dbaed6f4266056f186c34d3d19d8f9 (patch)
tree72abf8714901469ea048657797414e30f40175c0 /nix-script-channel-diff-generations.sh
parent9140a5cfe32a2fc57649f9436a6c5c0ee4b176ee (diff)
Add tool for diffing channel generations
Diffstat (limited to 'nix-script-channel-diff-generations.sh')
-rwxr-xr-xnix-script-channel-diff-generations.sh102
1 files changed, 102 insertions, 0 deletions
diff --git a/nix-script-channel-diff-generations.sh b/nix-script-channel-diff-generations.sh
new file mode 100755
index 0000000..5e65397
--- /dev/null
+++ b/nix-script-channel-diff-generations.sh
@@ -0,0 +1,102 @@
+#!/usr/bin/env bash
+
+source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh
+
+usage() {
+ cat <<EOS >&2
+ $(help_synopsis "${BASH_SOURCE[0]}" "[-g <command>] [-w <path>] [-n <generations>] [-h]")
+
+ -g <command> | Use this command instead of 'diff --name-only' (currently no support for multi-word args)
+ -w <path> | Path to working-copy of nixpkgs git repo, default: $RC_NIXPKGS
+ -n <generations> | Generations to show diff in form a..b
+ -h | Show this help and exit
+
+$(help_end)
+EOS
+}
+
+GEN_A=
+GEN_B=
+WC=$RC_NIXPKGS
+GIT="diff --name-only"
+
+explain() {
+ stdout $*
+ $*
+}
+
+while getopts "g:w:n:h" OPTION
+do
+ case $OPTION in
+ g)
+ GIT=$OPTARG
+ dbg "GIT = $GIT"
+ ;;
+
+ w)
+ WC=$OPTARG
+ dbg "WC = $WC"
+ ;;
+
+ n)
+ GEN_A=$(echo $OPTARG | cut -d "." -f 1)
+ GEN_B=$(echo $OPTARG | cut -d "." -f 3)
+
+ [[ -z "$GEN_A" || -z "$GEN_B" ]] && \
+ stderr "Parsing error for '$OPTARG'" && usage && exit 1
+
+ dbg "GEN_A = $GEN_A"
+ dbg "GEN_B = $GEN_B"
+ ;;
+
+ h)
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+[[ -z "$GEN_A" || -z "$GEN_B" ]] && \
+ stderr "No generation information" && usage && exit 1
+
+pathof() {
+ echo "/nix/var/nix/profiles/per-user/root/channels-$1-link/nixos/nixpkgs/.version-suffix"
+}
+
+version_string() {
+ local path=$(pathof $1)
+ local version=$(cat $path)
+
+ [[ -z "$version" ]] && \
+ stderr "No commit version information for generation $1" && exit 1
+
+ echo $version
+
+}
+
+commit_for() {
+ echo $(version_string $1) | cut -d . -f 2
+}
+
+__git() {
+ explain git --git-dir="$WC/.git" --work-tree="$WC" $*
+}
+
+A=$(commit_for $GEN_A)
+B=$(commit_for $GEN_B)
+
+stdout "A = $A"
+stdout "B = $B"
+
+[[ "$A" -eq "$B" ]] && \
+ echo "Same hash for both generations. There won't be a diff" && exit 1
+
+if [[ -z "$WC" ]]
+then
+ echo "$A..$B"
+else
+ __git $GIT "$A..$B"
+fi
+
+stdout "Ready"
+