Skip to content

Commit

Permalink
common-updater: support updating source URL
Browse files Browse the repository at this point in the history
  • Loading branch information
taku0 committed Mar 16, 2018
1 parent cb51341 commit 186de9c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkgs/applications/networking/browsers/firefox/update.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ writeScript "update-${attrPath}" ''
sort --version-sort | \
tail -n 1`
source_url=`curl --silent $url$version/SOURCE | grep -o 'https://.*\.tar\.bz2'`
shasum=`curl --silent $url$version/SHA512SUMS | grep 'source\.tar\.xz' | cut -d ' ' -f 1`
update-source-version ${attrPath} "$version" "$shasum"
update-source-version ${attrPath} "$version" "$shasum" "$source_url"
''
21 changes: 19 additions & 2 deletions pkgs/common-updater/scripts/update-source-version
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ die() {
exit 1
}

# Usage: update-source-hash <attr> <version> [<new-source-hash>]
# Usage: update-source-hash <attr> <version> [<new-source-hash>] [<new-source-url>]
attr=$1
newVersion=$2
newHash=$3
newUrl=$4

nixFile=$(nix-instantiate --eval --strict -A "$attr.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
if [ ! -f "$nixFile" ]; then
Expand All @@ -27,6 +28,12 @@ if [ $(grep -c "$oldHash" "$nixFile") != 1 ]; then
die "Couldn't locate old source hash '$oldHash' (or it appeared more than once) in '$nixFile'!"
fi

oldUrl=$(nix-instantiate --eval -E "with import ./. {}; builtins.elemAt $attr.src.drvAttrs.urls 0" | tr -d '"')

if [ -z "$oldUrl" ]; then
die "Couldn't evaluate source url from '$attr.name'!"
fi

drvName=$(nix-instantiate --eval -E "with import ./. {}; (builtins.parseDrvName $attr.name).name" | tr -d '"')
oldVersion=$(nix-instantiate --eval -E "with import ./. {}; $attr.version or (builtins.parseDrvName $attr.name).version" | tr -d '"')

Expand All @@ -41,6 +48,7 @@ fi

# Escape regex metacharacter that are allowed in store path names
oldVersion=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
oldUrl=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')

if [ $(grep -c -E "^\s*(let\b)?\s*version\s*=\s*\"$oldVersion\"" "$nixFile") = 1 ]; then
pattern="/\bversion\b\s*=/ s|\"$oldVersion\"|\"$newVersion\"|"
Expand All @@ -56,6 +64,15 @@ if cmp -s "$nixFile" "$nixFile.bak"; then
die "Failed to replace version '$oldVersion' to '$newVersion' in '$attr'!"
fi

# Replace new URL
if [ -n "$newUrl" ]; then
sed -i "$nixFile" -re "s|\"$oldUrl\"|\"$newUrl\"|"

if cmp -s "$nixFile" "$nixFile.bak"; then
die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!"
fi
fi

case "$oldHashAlgo" in
sha256) hashLength=64 ;;
sha512) hashLength=128 ;;
Expand All @@ -74,7 +91,7 @@ fi
if [ -z "$newHash" ]; then
nix-build --no-out-link -A "$attr.src" 2>"$attr.fetchlog" >/dev/null || true
# FIXME: use nix-build --hash here once https://github.com/NixOS/nix/issues/1172 is fixed
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)
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)
fi

if [ -z "$newHash" ]; then
Expand Down

0 comments on commit 186de9c

Please sign in to comment.