···11+#!/usr/bin/env bash
22+set -euo pipefail
33+44+# omnigent, omnigent-client and omnigent-ui-sdk are released in lockstep and
55+# all three are fetched as py3 wheels in package.nix; nix-update only bumps
66+# the top-level src, so bump all of them here.
77+attr=omnigent
88+99+# Run by update-pkgs from the flake root ($0 is a read-only store copy).
1010+pkg=pkgs/omnigent/package.nix
1111+system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
1212+1313+new_version=$(curl -fsSL https://pypi.org/pypi/omnigent/json | jq -r .info.version)
1414+old_version=$(sed -n 's|^ version = "\([^"]*\)";|\1|p' "$pkg")
1515+if [ "$old_version" = "$new_version" ]; then
1616+ echo "$attr: already up to date ($new_version)"
1717+ exit 0
1818+fi
1919+2020+# Hash of the py3-none-any wheel as published on PyPI, in SRI form.
2121+wheel_hash() {
2222+ local project=$1 hex
2323+ hex=$(curl -fsSL "https://pypi.org/pypi/$project/$new_version/json" |
2424+ jq -r '.urls[] | select(.packagetype == "bdist_wheel" and (.filename | endswith("-py3-none-any.whl"))) | .digests.sha256')
2525+ if [ -z "$hex" ]; then
2626+ echo "$attr: no py3-none-any wheel for $project $new_version" >&2
2727+ exit 1
2828+ fi
2929+ nix hash convert --hash-algo sha256 --to sri "$hex"
3030+}
3131+3232+# Replace the `hash = ...` that follows `pname = "<pname>"` (blanking first so
3333+# nothing ever builds against a stale cached FOD).
3434+set_hash() {
3535+ local pname=$1 hash=$2
3636+ sed -i "/pname = \"$pname\";/,/hash = /s|^\(\s*\)hash = \"[^\"]*\"|\1hash = \"$hash\"|" "$pkg"
3737+}
3838+3939+client_hash=$(wheel_hash omnigent-client)
4040+ui_sdk_hash=$(wheel_hash omnigent-ui-sdk)
4141+app_hash=$(wheel_hash omnigent)
4242+4343+sed -i \
4444+ -e "s|^\(\s*\)version = \"$old_version\";|\1version = \"$new_version\";|" \
4545+ -e "s|^\(\s*\)hash = \".*\"|\1hash = \"\"|" \
4646+ "$pkg"
4747+4848+set_hash omnigent_client "$client_hash"
4949+set_hash omnigent_ui_sdk "$ui_sdk_hash"
5050+set_hash omnigent "$app_hash"
5151+5252+if grep -q 'hash = ""' "$pkg"; then
5353+ echo "$attr: failed to fill in every hash" >&2
5454+ exit 1
5555+fi
5656+5757+echo "$attr: updated $old_version → $new_version"
5858+nix build --no-link ".#packages.$system.$attr"