forked from
lass.pds.lassul.us/superconfig
This repository has no description
2.8 kB
69 lines
1#!/usr/bin/env bash
2set -euo pipefail
3
4# Tangled has no releases for the knot-rs era and isn't on GitHub, so
5# nix-update can't follow it: bump src to the head of master, take the
6# frontend assets (the flake's *-src inputs) from its flake.lock and probe the
7# Go vendor and cargo hashes.
8attr=tangled
9url=https://tangled.org/tangled.org/core
10
11# Run by update-pkgs from the flake root ($0 is a read-only store copy).
12dir=pkgs/tangled
13pkg=$dir/package.nix
14# Linux-only package: always evaluate/build the x86_64-linux variant.
15build_attr=".#packages.x86_64-linux.$attr"
16
17new_rev=$(git ls-remote "$url" refs/heads/master | cut -f1)
18old_rev=$(sed -n 's|^ *rev = "\([^"]*\)";|\1|p' "$pkg")
19if [ "$old_rev" = "$new_rev" ]; then
20 echo "$attr: already up to date ($new_rev)"
21 exit 0
22fi
23
24# The flake fetcher's narHash is fetchgit's hash, and its store path has the
25# flake.lock with the asset pins.
26prefetch=$(nix flake prefetch --json "git+$url?rev=$new_rev")
27src_hash=$(jq -r .hash <<<"$prefetch")
28src_path=$(jq -r .storePath <<<"$prefetch")
29new_date=$(date -u -d "@$(jq -r .locked.lastModified <<<"$prefetch")" +%F)
30new_version="0-unstable-$new_date"
31
32jq '.nodes as $n
33 | [.nodes.root.inputs | to_entries[] | select(.key | endswith("-src"))
34 | { key, value: ($n[.value].locked
35 | { type, url } + (if .rev then { rev } else {} end) + { hash: .narHash }) }]
36 | sort_by(.key) | from_entries' "$src_path/flake.lock" >"$dir/assets.json"
37
38# Bump rev + version and blank the derived hashes: with the old ones in place
39# nix reuses the cached FODs and the build "succeeds" on stale code.
40sed -i \
41 -e "s|^\( *\)rev = \".*\";|\1rev = \"$new_rev\";|" \
42 -e "s|^\( *\)version = \".*\";|\1version = \"$new_version\";|" \
43 -e "s|^\( *\)hash = \"sha256-.*\";|\1hash = \"$src_hash\";|" \
44 -e "s|^\( *\)vendorHash = \".*\";|\1vendorHash = \"\";|" \
45 -e "s|^\( *\)cargoHash = \".*\";|\1cargoHash = \"\";|" \
46 "$pkg"
47
48# The probe build is *expected* to fail (hash mismatch); `|| true` keeps
49# pipefail/errexit from turning that into an empty `got`. awk must not
50# `exit` early or tee dies of SIGPIPE and takes the pipeline with it.
51probe_hash() {
52 { nix build --no-link "$build_attr$1" 2>&1 || true; } | tee /dev/stderr |
53 awk '/got:/ && !seen { print $2; seen = 1 }' || true
54}
55
56# Probe each FOD on its own so a hash is never attributed to the wrong field.
57for spec in vendorHash:.appview.goModules cargoHash:.knot-rs.cargoDeps; do
58 field=${spec%%:*}
59 got=$(probe_hash "${spec#*:}")
60 if [ -z "$got" ]; then
61 echo "$attr: no hash reported for $field" >&2
62 exit 1
63 fi
64 sed -i "s|^\( *\)$field = \"[^\"]*\";|\1$field = \"$got\";|" "$pkg"
65 echo "$attr: $field → $got"
66done
67
68echo "$attr: updated to $new_rev ($new_version)"
69nix build --no-link "$build_attr"