Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common-updater: use nix-prefetch-url to get new hash #31627

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkgs/common-updater/scripts.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, makeWrapper, coreutils, gawk, gnused, diffutils, nix }:
{ stdenv, makeWrapper, coreutils, gawk, gnused, diffutils, nix, curl, jq }:

stdenv.mkDerivation {
name = "common-updater-scripts";
Expand All @@ -12,7 +12,7 @@ stdenv.mkDerivation {
cp ${./scripts}/* $out/bin

for f in $out/bin/*; do
wrapProgram $f --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils gawk gnused nix diffutils ]}
wrapProgram $f --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils gawk gnused nix diffutils curl jq ]}
done
'';
}
22 changes: 17 additions & 5 deletions pkgs/common-updater/scripts/update-source-version
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
set -e
set -e -o pipefail

die() {
echo "$0: error: $1" >&2
exit 1
}

# Usage: update-source-hash <attr> <version> [<new-source-hash>]
# Usage: update-source-hash <attr> [<version>] [<new-source-hash>]
attr=$1
newVersion=$2
newHash=$3
Expand Down Expand Up @@ -34,6 +34,20 @@ if [ -z "$drvName" -o -z "$oldVersion" ]; then
die "Couldn't evaluate name and version from '$attr.name'!"
fi

if [ -z "$newVersion" ]; then
# works for fetchFromGitHub & fetchgit
url=$(nix-instantiate --eval --strict --expr "with import ./. {}; if $attr ? src.meta.homepage then $attr.src.meta.homepage else $attr.src.url")
if [[ -z "$url" ]] || ! [[ "$url" =~ \"https://github.com/([^\)]+)/([^\)/]+)\" ]]; then
die "we can only automatically check for new versions for github-based projects, got '$url'"
fi
owner=${BASH_REMATCH[1]}
repo=${BASH_REMATCH[2]%.git}
newVersion=$(curl -s "https://api.github.com/repos/${owner}/${repo}/tags" | jq -r '.[0]?.name | gsub("^v"; "")')
if [[ $newVersion == "" ]]; then
die "no tags found for $url"
fi
fi

if [ "$oldVersion" = "$newVersion" ]; then
echo "$0: New version same as old version, nothing to do." >&2
exit 0
Expand Down Expand Up @@ -72,9 +86,7 @@ fi

# If new hash not given on the command line, recalculate it ourselves.
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=$(tail -n2 "$attr.fetchlog" | grep "output path .* has .* hash .* when .* was expected" | head -n1 | tr -dc '\040-\177' | awk '{ print $(NF-4) }')
newHash=$(nix-prefetch-url -A "$attr.src" 2>"$attr.fetchlog")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also replaced hashes contained enclosing ' characters before.

fi

if [ -z "$newHash" ]; then
Expand Down
4 changes: 2 additions & 2 deletions pkgs/games/trackballs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ with stdenv.lib;

stdenv.mkDerivation rec {
name = "trackballs-${version}";
version = "1.2.3";
version = "1.2.4";

src = fetchFromGitHub {
owner = "trackballs";
repo = "trackballs";
rev = "v${version}";
sha256 = "13f28frni7fkalxx4wqvmkzz7ba3d8pic9f9sd2z9wa6gbjs9zrf";
sha256 = "0y5y8xzfsjd0rxl5wnxdq7m9n97s5xvcqyjsckz4qxrjcc3lk297";
};

buildInputs = [ cmake zlib SDL2 SDL2_ttf SDL2_mixer SDL2_image guile gettext mesa ];
Expand Down