From 71c3187076c8635b21e5b5d326642cc39a74d41f Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Tue, 29 Jul 2025 11:31:44 -0700 Subject: [PATCH 1/5] nix-prefetch-scripts: add nix-prefetch-fossil Add a nix-prefetch-fossil script that follows the same pattern as the existing nix-prefetch-git, nix-prefetch-hg, etc. scripts. This allows users to easily fetch Fossil repositories and calculate their hashes for use with fetchfossil in Nix expressions. The script supports: - Fetching from Fossil repository URLs - Specifying revisions (defaults to "trunk") - Checking expected hashes - JSON output compatible with other nix-prefetch scripts --- .../fetchfossil/nix-prefetch-fossil | 125 ++++++++++++++++++ .../nix-prefetch-scripts/default.nix | 7 + 2 files changed, 132 insertions(+) create mode 100755 pkgs/build-support/fetchfossil/nix-prefetch-fossil diff --git a/pkgs/build-support/fetchfossil/nix-prefetch-fossil b/pkgs/build-support/fetchfossil/nix-prefetch-fossil new file mode 100755 index 000000000000..1f3c2636355e --- /dev/null +++ b/pkgs/build-support/fetchfossil/nix-prefetch-fossil @@ -0,0 +1,125 @@ +#!/bin/sh -e + +url= +rev= +expHash= +hashType="${NIX_HASH_ALGO:-sha256}" + +# Parse command line arguments +argi=0 +argfun="" +for arg; do + if test -z "$argfun"; then + case $arg in + --url) argfun=set_url;; + --rev) argfun=set_rev;; + --hash) argfun=set_expHash;; + --help|-h) + echo "Usage: nix-prefetch-fossil [options] [URL [REVISION [EXPECTED-HASH]]]" + echo "" + echo "Options:" + echo " --url URL Fossil repository URL" + echo " --rev REV Fossil revision/tag/branch (default: trunk)" + echo " --hash HASH Expected hash" + echo " --help Show this help message" + exit 0 + ;; + *) + argi=$((argi + 1)) + case $argi in + 1) url=$arg;; + 2) rev=$arg;; + 3) expHash=$arg;; + *) echo "Too many arguments" >&2; exit 1;; + esac + ;; + esac + else + case $argfun in + set_*) + var=${argfun#set_} + eval "$var='$arg'" + ;; + esac + argfun="" + fi +done + +if test -z "$url"; then + echo "error: URL is required" >&2 + echo "Usage: nix-prefetch-fossil [URL [REVISION [EXPECTED-HASH]]]" >&2 + exit 1 +fi + +# Default to trunk if no revision specified +if test -z "$rev"; then + rev="trunk" +fi + +# If the hash was given, check if we already have it in store +if test -n "$expHash"; then + finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" fossil-archive) + if nix-store --check-validity "$finalPath" 2> /dev/null; then + echo "$expHash" + exit 0 + fi +fi + +# Create temporary directory for cloning +tmpPath="$(mktemp -d --tmpdir fossil-checkout-tmp-XXXXXXXX)" +cleanup() { rm -rf "$tmpPath"; } +trap cleanup EXIT + +# Fossil wants to write global configuration to $HOME/.fossil +# We'll let it write to the temp directory instead +export HOME="$tmpPath" + +echo "Fetching Fossil repository $url at revision $rev..." >&2 + +# Clone the repository +fossil clone -A nobody "$url" "$tmpPath/fossil-clone.fossil" >&2 + +# Create directory for checkout +checkoutDir="$tmpPath/checkout" +mkdir -p "$checkoutDir" + +# Open the repository at the specified revision +cd "$checkoutDir" +fossil open "$tmpPath/fossil-clone.fossil" "$rev" >&2 + +# Get the actual commit hash and date +checkoutLine=$(fossil info | grep ^checkout:) +# Remove 'checkout:' prefix and squeeze multiple spaces, then extract fields +actualRev=$(echo "$checkoutLine" | sed 's/^checkout:[[:space:]]*//' | tr -s ' ' | cut -d' ' -f1) +# Extract date (format: checkout: HASH YYYY-MM-DD HH:MM:SS UTC) +actualDate=$(echo "$checkoutLine" | sed 's/^checkout:[[:space:]]*//' | tr -s ' ' | cut -d' ' -f2) +cd - >/dev/null + +# Remove the fossil checkout file +rm -f "$checkoutDir/.fslckout" + +# Calculate the hash +hash=$(nix-hash --type "$hashType" --base32 "$checkoutDir") +echo "hash is $hash" >&2 + +# Add to store if we don't have an expected hash or if it matches +if test -z "$expHash" || test "$expHash" = "$hash"; then + finalPath=$(nix-store --add-fixed --recursive "$hashType" "$checkoutDir") + echo "path is $finalPath" >&2 +elif test -n "$expHash" && test "$expHash" != "$hash"; then + echo "error: hash mismatch for Fossil repository $url" >&2 + echo " expected: $expHash" >&2 + echo " actual: $hash" >&2 + exit 1 +fi + +# Output JSON result +cat < Date: Tue, 29 Jul 2025 12:10:51 -0700 Subject: [PATCH 2/5] althttpd: add updateScript --- pkgs/by-name/al/althttpd/package.nix | 3 +++ pkgs/by-name/al/althttpd/update.sh | 40 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 pkgs/by-name/al/althttpd/update.sh diff --git a/pkgs/by-name/al/althttpd/package.nix b/pkgs/by-name/al/althttpd/package.nix index f467d0fd03f1..3faf0c936441 100644 --- a/pkgs/by-name/al/althttpd/package.nix +++ b/pkgs/by-name/al/althttpd/package.nix @@ -3,6 +3,7 @@ stdenv, fetchfossil, openssl, + nix-update-script, }: stdenv.mkDerivation { @@ -23,6 +24,8 @@ stdenv.mkDerivation { install -Dm755 -t $out/bin althttpd ''; + passthru.updateScript = ./update.sh; + meta = { description = "Althttpd webserver"; homepage = "https://sqlite.org/althttpd/"; diff --git a/pkgs/by-name/al/althttpd/update.sh b/pkgs/by-name/al/althttpd/update.sh new file mode 100755 index 000000000000..66cb9c236d63 --- /dev/null +++ b/pkgs/by-name/al/althttpd/update.sh @@ -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 althttpd revision..." >&2 + +# Run nix-prefetch-fossil and capture output +output=$("$prefetch_fossil" https://sqlite.org/althttpd 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="unstable-$commit_date" + +echo "Updating althttpd to $new_version (rev $new_rev)" >&2 + +# Use update-source-version from the nixpkgs root +( + cd "$nixpkgs" + update-source-version althttpd "$new_version" "$new_hash" \ + --file="pkgs/by-name/al/althttpd/package.nix" \ + --rev="$new_rev" +) From 548a2cb7c872c8d5e4574ce7fe53de358dfc886f Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Tue, 29 Jul 2025 12:21:04 -0700 Subject: [PATCH 3/5] althttpd: unstable-2023-08-12 -> unstable-2025-08-22 --- pkgs/by-name/al/althttpd/package.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/al/althttpd/package.nix b/pkgs/by-name/al/althttpd/package.nix index 3faf0c936441..e8148aa18a5c 100644 --- a/pkgs/by-name/al/althttpd/package.nix +++ b/pkgs/by-name/al/althttpd/package.nix @@ -8,12 +8,12 @@ stdenv.mkDerivation { pname = "althttpd"; - version = "0-unstable-2023-08-12"; + version = "0-unstable-2025-08-22"; src = fetchfossil { url = "https://sqlite.org/althttpd/"; - rev = "c0bdc68e6c56ef25"; - hash = "sha256-VoDR5MlVlvar9wYA0kUhvDQVjxDwsZlqrNR3u4Tqw5c="; + rev = "e9bf26f78e1f5792"; + hash = "sha256-Q16tqhnPzYrFkrHTC8NBrdpsbrpjPUkdxLwmyYqUHZo="; }; buildInputs = [ openssl ]; From 916dcf96aaa74683bf3faf7ddfdf9464c765da79 Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Tue, 29 Jul 2025 12:36:01 -0700 Subject: [PATCH 4/5] pikchr: add update script --- pkgs/by-name/pi/pikchr/package.nix | 2 ++ pkgs/by-name/pi/pikchr/update.sh | 40 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 pkgs/by-name/pi/pikchr/update.sh diff --git a/pkgs/by-name/pi/pikchr/package.nix b/pkgs/by-name/pi/pikchr/package.nix index 97a0185323a2..f89061a31ba0 100644 --- a/pkgs/by-name/pi/pikchr/package.nix +++ b/pkgs/by-name/pi/pikchr/package.nix @@ -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"; diff --git a/pkgs/by-name/pi/pikchr/update.sh b/pkgs/by-name/pi/pikchr/update.sh new file mode 100755 index 000000000000..c565ab5cce6b --- /dev/null +++ b/pkgs/by-name/pi/pikchr/update.sh @@ -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" +) From d12ba66216a59a62c03052b0ff944f5fbe79bb5d Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Tue, 29 Jul 2025 12:37:20 -0700 Subject: [PATCH 5/5] pikchr: unstable-2025-02-28 -> unstable-2025-05-12 --- pkgs/by-name/pi/pikchr/package.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/pi/pikchr/package.nix b/pkgs/by-name/pi/pikchr/package.nix index f89061a31ba0..02ae12243c53 100644 --- a/pkgs/by-name/pi/pikchr/package.nix +++ b/pkgs/by-name/pi/pikchr/package.nix @@ -10,12 +10,12 @@ stdenv.mkDerivation { pname = "pikchr"; # To update, use the last check-in in https://pikchr.org/home/timeline?r=trunk - version = "0-unstable-2025-02-28"; + version = "0-unstable-2025-05-12"; src = fetchfossil { url = "https://pikchr.org/home"; - rev = "b7fbd56c4eb82ab9"; - hash = "sha256-7oW1IYYk3YKPjOUPP6qYIdR0oGo9pRDDlyu30J4B3bI="; + rev = "2972d1d24849d4c3"; + hash = "sha256-IZ9m1xa2bO9Sd6XYROkNz6PloLEbR3d3JpSSYyDJR8I="; }; # can't open generated html files