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 </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" +) diff --git a/pkgs/by-name/pi/pikchr/package.nix b/pkgs/by-name/pi/pikchr/package.nix index 97a0185323a2..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 @@ -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" +) diff --git a/pkgs/tools/package-management/nix-prefetch-scripts/default.nix b/pkgs/tools/package-management/nix-prefetch-scripts/default.nix index e9c692d57f8e..64a94eb494d3 100644 --- a/pkgs/tools/package-management/nix-prefetch-scripts/default.nix +++ b/pkgs/tools/package-management/nix-prefetch-scripts/default.nix @@ -10,6 +10,7 @@ cvs, darcs, findutils, + fossil, gawk, gitMinimal, git-lfs, @@ -65,6 +66,11 @@ rec { gawk jq ]; + nix-prefetch-fossil = + mkPrefetchScript "fossil" ../../../build-support/fetchfossil/nix-prefetch-fossil + [ + fossil + ]; nix-prefetch-git = mkPrefetchScript "git" ../../../build-support/fetchgit/nix-prefetch-git [ findutils gawk @@ -94,6 +100,7 @@ rec { nix-prefetch-bzr nix-prefetch-cvs nix-prefetch-darcs + nix-prefetch-fossil nix-prefetch-git nix-prefetch-hg nix-prefetch-svn