pikchr: add update script

This commit is contained in:
Ben Siraphob
2025-07-29 12:36:01 -07:00
parent 548a2cb7c8
commit 916dcf96aa
2 changed files with 42 additions and 0 deletions
+2
View File
@@ -48,6 +48,8 @@ stdenv.mkDerivation {
doCheck = true;
passthru.updateScript = ./update.sh;
meta = {
description = "PIC-like markup language for diagrams in technical documentation";
homepage = "https://pikchr.org";
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p common-updater-scripts jq gawk
set -euo pipefail
nixpkgs="$(git rev-parse --show-toplevel)"
cd "$(dirname "${BASH_SOURCE[0]}")"
# Build and run nix-prefetch-fossil from the local nixpkgs
prefetch_fossil="$(nix-build "$nixpkgs" -A nix-prefetch-scripts --no-out-link 2>/dev/null)/bin/nix-prefetch-fossil"
echo "Fetching latest pikchr revision..." >&2
# Run nix-prefetch-fossil and capture output
output=$("$prefetch_fossil" https://pikchr.org/home trunk 2>&1)
# Extract JSON from output (it's at the end after the blank line)
json_output=$(echo "$output" | gawk '/^{/{p=1} p')
# Extract revision, hash, and date
full_rev=$(echo "$json_output" | jq -r '.rev')
new_rev="${full_rev:0:16}" # Use 16-char prefix for consistency
new_hash=$(echo "$json_output" | jq -r '.hash')
commit_date=$(echo "$json_output" | jq -r '.date')
# Fallback to current date if extraction fails
if [ -z "$commit_date" ] || [ "$commit_date" = "null" ]; then
commit_date=$(date +%Y-%m-%d)
fi
new_version="0-unstable-$commit_date"
echo "Updating pikchr to $new_version (rev $new_rev)" >&2
# Use update-source-version from the nixpkgs root
(
cd "$nixpkgs"
update-source-version pikchr "$new_version" "$new_hash" \
--file="pkgs/by-name/pi/pikchr/package.nix" \
--rev="$new_rev"
)