This repository has no description
2.6 kB
79 lines
1#!/usr/bin/env bash
2set -euo pipefail
3
4# Two cgit sources (reaktor2 + its blessings dependency) bumped together to
5# their latest release tags; nix-update can't handle the pair.
6attr=reaktor2
7
8# Run by update-pkgs from the flake root ($0 is a read-only store copy).
9dir=pkgs/reaktor2
10system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
11build_attr=".#packages.$system.$attr"
12
13# Prints "<tag> <rev>" of the highest version tag (tags may or may not carry a
14# leading "v"; annotated tags resolve to the commit via ^{}).
15latest_tag() {
16 git ls-remote --tags "$1" |
17 awk '{ ref = $2; sub("^refs/tags/", "", ref); peeled = sub("\\^\\{\\}$", "", ref)
18 if (peeled || !(ref in rev)) rev[ref] = $1 }
19 END { for (t in rev) { v = t; sub("^v", "", v); print v, t, rev[t] } }' |
20 sort -V -k1,1 | tail -n1 | cut -d' ' -f2-
21}
22
23changed=()
24bump() {
25 local name=$1 file=$dir/$2
26 local tag rev old_rev version
27 read -r tag rev < <(latest_tag "https://cgit.krebsco.de/$name")
28 version=${tag#v}
29 old_rev=$(sed -n 's/^ *rev = "\([^"]*\)".*/\1/p' "$file")
30 if [ "$old_rev" = "$rev" ]; then
31 return
32 fi
33 # Blank the hash too: with the old one in place nix reuses the cached FOD.
34 sed -i \
35 -e "s|^\( *\)rev = \".*\"|\1rev = \"$rev\"|" \
36 -e "s|^\( *\)version = \".*\"|\1version = \"$version\"|" \
37 -e "s|^\( *\)sha256 = \".*\"|\1sha256 = \"\"|" \
38 "$file"
39 changed+=("$name")
40 echo "$name: $old_rev -> $rev ($version)"
41}
42
43bump blessings blessings.nix
44bump reaktor2 reaktor2.nix
45
46if [ ${#changed[@]} -eq 0 ]; then
47 echo "$attr: already up to date"
48 exit 0
49fi
50
51# The probe build is *expected* to fail with a hash mismatch; print
52# "<drv-name> <got-hash>" of the first mismatching source. awk must not exit
53# early or tee dies of SIGPIPE.
54probe_hash() {
55 { nix build --no-link "$build_attr" 2>&1 || true; } | tee /dev/stderr |
56 awk '/hash mismatch in fixed-output derivation/ && !drv { match($0, /\/nix\/store\/[a-z0-9]+-[^'"'"']*/); drv = substr($0, RSTART + 44, RLENGTH - 44) }
57 /got:/ && drv && !seen { print drv, $2; seen = 1 }' || true
58}
59
60for _ in "${changed[@]}"; do
61 read -r drv got < <(probe_hash) || true
62 if [ -z "${got:-}" ]; then
63 break
64 fi
65 case $drv in
66 blessings*) file=$dir/blessings.nix ;;
67 reaktor2*) file=$dir/reaktor2.nix ;;
68 *)
69 echo "$attr: unexpected hash mismatch in $drv" >&2
70 exit 1
71 ;;
72 esac
73 sed -i "s|^\( *\)sha256 = \"[^\"]*\"|\1sha256 = \"$got\"|" "$file"
74 echo "$attr: $drv hash -> $got"
75 got=
76done
77
78nix build --no-link "$build_attr"
79echo "$attr: updated ${changed[*]}"