@@ -6,10 +6,11 @@ die() {
66 exit 1
77}
88
9−# Usage: update-source-hash <attr> <version> [<new-source-hash>]
9+# Usage: update-source-hash <attr> <version> [<new-source-hash>] [<new-source-url>]
1010attr=$1
1111newVersion=$2
1212newHash=$3
13+newUrl=$4
1314
1415nixFile=$(nix-instantiate --eval --strict -A "$attr.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
1516if [ ! -f "$nixFile" ]; then
@@ -27,6 +28,12 @@ if [ $(grep -c "$oldHash" "$nixFile") != 1 ]; then
2728 die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
2829fi
2930
31+oldUrl=$(nix-instantiate --eval -E "with import ./. {}; builtins.elemAt $attr.src.drvAttrs.urls 0" | tr -d '"')
32+
33+if [ -z "$oldUrl" ]; then
34+ die "Couldn't evaluate source url from '$attr.name'!"
35+fi
36+
3037drvName=$(nix-instantiate --eval -E "with import ./. {}; (builtins.parseDrvName $attr.name).name" | tr -d '"')
3138oldVersion=$(nix-instantiate --eval -E "with import ./. {}; $attr.version or (builtins.parseDrvName $attr.name).version" | tr -d '"')
3239
@@ -41,6 +48,7 @@ fi
4148
4249# Escape regex metacharacter that are allowed in store path names
4350oldVersion=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
51+oldUrl=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
4452
4553if [ $(grep -c -E "^\s*(let\b)?\s*version\s*=\s*\"$oldVersion\"" "$nixFile") = 1 ]; then
4654 pattern="/\bversion\b\s*=/ s|\"$oldVersion\"|\"$newVersion\"|"
@@ -56,6 +64,15 @@ if cmp -s "$nixFile" "$nixFile.bak"; then
5664 die "Failed to replace version '$oldVersion' to '$newVersion' in '$attr'!"
5765fi
5866
67+# Replace new URL
68+if [ -n "$newUrl" ]; then
69+ sed -i "$nixFile" -re "s|\"$oldUrl\"|\"$newUrl\"|"
70+
71+ if cmp -s "$nixFile" "$nixFile.bak"; then
72+ die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!"
73+ fi
74+fi
75+
5976case "$oldHashAlgo" in
6077 sha256) hashLength=64 ;;
6178 sha512) hashLength=128 ;;
@@ -74,7 +91,7 @@ fi
7491if [ -z "$newHash" ]; then
7592 nix-build --no-out-link -A "$attr.src" 2>"$attr.fetchlog" >/dev/null || true
7693 # FIXME: use nix-build --hash here once https://github.com/NixOS/nix/issues/1172 is fixed
77− newHash=$(egrep -v "killing process|dependencies couldn't be built" "$attr.fetchlog" | tail -n2 | sed "s~output path .* has .* hash \(.*\) when .* was expected\|fixed-output derivation produced path '.*' with .* hash '\(.*\)' instead of the expected hash '.*'~\1\2~" | head -n1)
94+ newHash=$(egrep -v "killing process|dependencies couldn't be built" "$attr.fetchlog" | tail -n2 | sed "s~output path .* has .* hash ‘\(.*\)’ when .* was expected\|fixed-output derivation produced path '.*' with .* hash '\(.*\)' instead of the expected hash '.*'~\1\2~" | head -n1)
7895fi
7996
8097if [ -z "$newHash" ]; then