summaryrefslogtreecommitdiffstats
path: root/pkgs/common-updater/scripts
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2021-12-31 06:54:09 +0100
committerJan Tojnar <jtojnar@gmail.com>2021-12-31 06:54:42 +0100
commitd9dea8d2a9ce5ac08f03fb23d36104cbe8028583 (patch)
treee39fd1e6dc1f2db6cec39abdd99c58bffce49bfb /pkgs/common-updater/scripts
parent3448c93da450316f9f87186517554b18d1209f5b (diff)
common-updater-scripts: allow using different src attribute
Useful for packages with multiple sources.
Diffstat (limited to 'pkgs/common-updater/scripts')
-rwxr-xr-xpkgs/common-updater/scripts/update-source-version30
1 files changed, 19 insertions, 11 deletions
diff --git a/pkgs/common-updater/scripts/update-source-version b/pkgs/common-updater/scripts/update-source-version
index 0ac6b3cf8c28..2b890bc3dc17 100755
--- a/pkgs/common-updater/scripts/update-source-version
+++ b/pkgs/common-updater/scripts/update-source-version
@@ -10,7 +10,8 @@ die() {
usage() {
echo "Usage: $scriptName <attr> <version> [<new-source-hash>] [<new-source-url>]"
- echo " [--version-key=<version-key>] [--system=<system>] [--file=<file-to-update>] [--rev=<revision>]"
+ echo " [--version-key=<version-key>] [--source-key=<source-key>]"
+ echo " [--system=<system>] [--file=<file-to-update>] [--rev=<revision>]"
echo " [--ignore-same-hash] [--print-changes]"
}
@@ -25,6 +26,9 @@ for arg in "$@"; do
--version-key=*)
versionKey="${arg#*=}"
;;
+ --source-key=*)
+ sourceKey="${arg#*=}"
+ ;;
--file=*)
nixFile="${arg#*=}"
if [[ ! -f "$nixFile" ]]; then
@@ -79,6 +83,10 @@ if [[ -z "$versionKey" ]]; then
versionKey=version
fi
+if [[ -z "$sourceKey" ]]; then
+ sourceKey=src
+fi
+
# Allow finding packages among flake outputs in repos using flake-compat.
pname=$(nix-instantiate $systemArg --eval --strict -A "$attr.name" || echo)
if [[ -z "$pname" ]]; then
@@ -114,21 +122,21 @@ if [[ -z "$nixFile" ]]; then
fi
fi
-oldHashAlgo=$(nix-instantiate $systemArg --eval --strict -A "$attr.src.drvAttrs.outputHashAlgo" | tr -d '"')
-oldHash=$(nix-instantiate $systemArg --eval --strict -A "$attr.src.drvAttrs.outputHash" | tr -d '"')
+oldHashAlgo=$(nix-instantiate $systemArg --eval --strict -A "$attr.$sourceKey.drvAttrs.outputHashAlgo" | tr -d '"')
+oldHash=$(nix-instantiate $systemArg --eval --strict -A "$attr.$sourceKey.drvAttrs.outputHash" | tr -d '"')
if [[ -z "$oldHashAlgo" || -z "$oldHash" ]]; then
- die "Couldn't evaluate old source hash from '$attr.src'!"
+ die "Couldn't evaluate old source hash from '$attr.$sourceKey'!"
fi
if [[ $(grep --count "$oldHash" "$nixFile") != 1 ]]; then
die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
fi
-oldUrl=$(nix-instantiate $systemArg --eval -E "with $importTree; builtins.elemAt ($attr.src.drvAttrs.urls or [ $attr.src.url ]) 0" | tr -d '"')
+oldUrl=$(nix-instantiate $systemArg --eval -E "with $importTree; builtins.elemAt ($attr.$sourceKey.drvAttrs.urls or [ $attr.$sourceKey.url ]) 0" | tr -d '"')
if [[ -z "$oldUrl" ]]; then
- die "Couldn't evaluate source url from '$attr.src'!"
+ die "Couldn't evaluate source url from '$attr.$sourceKey'!"
fi
oldVersion=$(nix-instantiate $systemArg --eval -E "with $importTree; $attr.${versionKey} or (builtins.parseDrvName $attr.name).version" | tr -d '"')
@@ -146,9 +154,9 @@ if [[ "$oldVersion" = "$newVersion" ]]; then
fi
if [[ -n "$newRevision" ]]; then
- oldRevision=$(nix-instantiate $systemArg --eval -E "with $importTree; $attr.src.rev" | tr -d '"')
+ oldRevision=$(nix-instantiate $systemArg --eval -E "with $importTree; $attr.$sourceKey.rev" | tr -d '"')
if [[ -z "$oldRevision" ]]; then
- die "Couldn't evaluate source revision from '$attr.src'!"
+ die "Couldn't evaluate source revision from '$attr.$sourceKey'!"
fi
fi
@@ -228,7 +236,7 @@ fi
# If new hash not given on the command line, recalculate it ourselves.
if [[ -z "$newHash" ]]; then
- nix-build $systemArg --no-out-link -A "$attr.src" 2>"$attr.fetchlog" >/dev/null || true
+ nix-build $systemArg --no-out-link -A "$attr.$sourceKey" 2>"$attr.fetchlog" >/dev/null || true
# FIXME: use nix-build --hash here once https://github.com/NixOS/nix/issues/1172 is fixed
newHash=$(sed '1,/hash mismatch in fixed-output derivation/d' "$attr.fetchlog" | grep --perl-regexp --only-matching 'got: +.+[:-]\K.+')
@@ -242,12 +250,12 @@ fi
if [[ -z "$newHash" ]]; then
cat "$attr.fetchlog" >&2
- die "Couldn't figure out new hash of '$attr.src'!"
+ die "Couldn't figure out new hash of '$attr.$sourceKey'!"
fi
if [[ -z "${ignoreSameHash}" && "$oldVersion" != "$newVersion" && "$oldHash" = "$newHash" ]]; then
mv "$nixFile.bak" "$nixFile"
- die "Both the old and new source hashes of '$attr.src' were equivalent. Please fix the package's source URL to be dependent on '\${version}'!"
+ die "Both the old and new source hashes of '$attr.$sourceKey' were equivalent. Please fix the package's source URL to be dependent on '\${version}'!"
fi
sed -i "$nixFile" -re "s|\"$tempHashEscaped\"|\"$newHash\"|"