mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
common-updater-scripts: allow using different src attribute
Useful for packages with multiple sources.
This commit is contained in:
parent
3448c93da4
commit
d9dea8d2a9
@ -10,7 +10,8 @@ die() {
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $scriptName <attr> <version> [<new-source-hash>] [<new-source-url>]"
|
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]"
|
echo " [--ignore-same-hash] [--print-changes]"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +26,9 @@ for arg in "$@"; do
|
|||||||
--version-key=*)
|
--version-key=*)
|
||||||
versionKey="${arg#*=}"
|
versionKey="${arg#*=}"
|
||||||
;;
|
;;
|
||||||
|
--source-key=*)
|
||||||
|
sourceKey="${arg#*=}"
|
||||||
|
;;
|
||||||
--file=*)
|
--file=*)
|
||||||
nixFile="${arg#*=}"
|
nixFile="${arg#*=}"
|
||||||
if [[ ! -f "$nixFile" ]]; then
|
if [[ ! -f "$nixFile" ]]; then
|
||||||
@ -79,6 +83,10 @@ if [[ -z "$versionKey" ]]; then
|
|||||||
versionKey=version
|
versionKey=version
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$sourceKey" ]]; then
|
||||||
|
sourceKey=src
|
||||||
|
fi
|
||||||
|
|
||||||
# Allow finding packages among flake outputs in repos using flake-compat.
|
# Allow finding packages among flake outputs in repos using flake-compat.
|
||||||
pname=$(nix-instantiate $systemArg --eval --strict -A "$attr.name" || echo)
|
pname=$(nix-instantiate $systemArg --eval --strict -A "$attr.name" || echo)
|
||||||
if [[ -z "$pname" ]]; then
|
if [[ -z "$pname" ]]; then
|
||||||
@ -114,21 +122,21 @@ if [[ -z "$nixFile" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
oldHashAlgo=$(nix-instantiate $systemArg --eval --strict -A "$attr.src.drvAttrs.outputHashAlgo" | tr -d '"')
|
oldHashAlgo=$(nix-instantiate $systemArg --eval --strict -A "$attr.$sourceKey.drvAttrs.outputHashAlgo" | tr -d '"')
|
||||||
oldHash=$(nix-instantiate $systemArg --eval --strict -A "$attr.src.drvAttrs.outputHash" | tr -d '"')
|
oldHash=$(nix-instantiate $systemArg --eval --strict -A "$attr.$sourceKey.drvAttrs.outputHash" | tr -d '"')
|
||||||
|
|
||||||
if [[ -z "$oldHashAlgo" || -z "$oldHash" ]]; then
|
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
|
fi
|
||||||
|
|
||||||
if [[ $(grep --count "$oldHash" "$nixFile") != 1 ]]; then
|
if [[ $(grep --count "$oldHash" "$nixFile") != 1 ]]; then
|
||||||
die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
|
die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
|
||||||
fi
|
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
|
if [[ -z "$oldUrl" ]]; then
|
||||||
die "Couldn't evaluate source url from '$attr.src'!"
|
die "Couldn't evaluate source url from '$attr.$sourceKey'!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
oldVersion=$(nix-instantiate $systemArg --eval -E "with $importTree; $attr.${versionKey} or (builtins.parseDrvName $attr.name).version" | tr -d '"')
|
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
|
fi
|
||||||
|
|
||||||
if [[ -n "$newRevision" ]]; then
|
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
|
if [[ -z "$oldRevision" ]]; then
|
||||||
die "Couldn't evaluate source revision from '$attr.src'!"
|
die "Couldn't evaluate source revision from '$attr.$sourceKey'!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -228,7 +236,7 @@ fi
|
|||||||
|
|
||||||
# If new hash not given on the command line, recalculate it ourselves.
|
# If new hash not given on the command line, recalculate it ourselves.
|
||||||
if [[ -z "$newHash" ]]; then
|
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
|
# 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.+')
|
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
|
if [[ -z "$newHash" ]]; then
|
||||||
cat "$attr.fetchlog" >&2
|
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
|
fi
|
||||||
|
|
||||||
if [[ -z "${ignoreSameHash}" && "$oldVersion" != "$newVersion" && "$oldHash" = "$newHash" ]]; then
|
if [[ -z "${ignoreSameHash}" && "$oldVersion" != "$newVersion" && "$oldHash" = "$newHash" ]]; then
|
||||||
mv "$nixFile.bak" "$nixFile"
|
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
|
fi
|
||||||
|
|
||||||
sed -i "$nixFile" -re "s|\"$tempHashEscaped\"|\"$newHash\"|"
|
sed -i "$nixFile" -re "s|\"$tempHashEscaped\"|\"$newHash\"|"
|
||||||
|
Loading…
Reference in New Issue
Block a user