This repository has no description
1.5 kB
44 lines
1#!/usr/bin/env bash
2set -euo pipefail
3
4# Tracks the default branch (dev) of audibleblink/worldview.
5# nix-update can't edit this flake-module.nix (no package.nix / meta.position).
6owner=audibleblink
7repo=worldview
8attr=worldview
9
10# Run by update-pkgs from the flake root ($0 is a read-only store copy).
11file=tools/worldview/flake-module.nix
12# Depends on ungoogled-chromium, which only evaluates on Linux.
13system=x86_64-linux
14
15commit=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/HEAD")
16new_rev=$(jq -r .sha <<<"$commit")
17new_date=$(jq -r .commit.committer.date <<<"$commit" | cut -d T -f1)
18new_version="0-unstable-$new_date"
19old_rev=$(sed -n 's/^ *rev = "\([0-9a-f]*\)";/\1/p' "$file")
20if [ "$old_rev" = "$new_rev" ]; then
21 echo "$attr: already up to date ($new_rev)"
22 exit 0
23fi
24
25# Blank the hash: with the old one nix reuses the cached FOD (old source).
26sed -i \
27 -e "s|^\( *\)rev = \"[0-9a-f]*\";|\1rev = \"$new_rev\";|" \
28 -e "s|^\( *\)version = \"[^\"]*\";|\1version = \"$new_version\";|" \
29 -e "s|^\( *\)hash = \"[^\"]*\";|\1hash = \"\";|" \
30 "$file"
31
32build_attr=".#packages.$system.$attr"
33
34# Probe build is expected to fail with a hash mismatch.
35got=$({ nix build --no-link "$build_attr" 2>&1 || true; } | tee /dev/stderr \
36 | awk '/got:/ && !seen { print $2; seen = 1 }' || true)
37if [ -z "$got" ]; then
38 echo "$attr: failed to determine src hash" >&2
39 exit 1
40fi
41sed -i "s|^\( *\)hash = \"\";|\1hash = \"$got\";|" "$file"
42
43echo "$attr: updated $old_rev -> $new_rev ($new_version)"
44nix build --no-link "$build_attr"