#!/usr/bin/env bash # Update flow for gitea-local-fork driven by passthru.updateScript. # Invoked by `nix-update --use-update-script gitea-local-fork`. # # Source fork: /home/oleks/projects/gitea # Source remote: https://git.oleks.space/oleks/gitea.git (named `oleks` locally) # Tracked branch: oleks/main (formerly `feat/projects-api`, renamed 2026-05-13) # # nix-update with --version=branch=X constructs the new version as # `-unstable-` where is the most recent # tag on the remote. If we leave an old `v1.26.0-unstable-` tag # from a previous run on the gitea fork, nix-update will pick that # as and we end up with double suffixes. So: # # 0. Delete any prior `*-unstable-*` tag on the gitea fork (local + remote). # 1. Run nix-update default flow: it now sees only clean semver tags # (v1.26.0 etc.), constructs `1.26.0-unstable-`. # 2. Tag the gitea fork at the new rev with v, push the tag. # 3. Commit flake-hub's package.nix change, push to origin. set -euo pipefail FLAKE_HUB="${FLAKE_HUB:-$HOME/projects/nix-customs/flake-hub}" GITEA_REPO="${GITEA_REPO:-$HOME/projects/gitea}" PKG_FILE="$FLAKE_HUB/packages/gitea-local-fork.nix" log() { printf '\033[1;36m==>\033[0m %s\n' "$*"; } # ── 0. Wipe prior unstable tags from gitea fork ─────────────────────────── cd "$GITEA_REPO" log "Cleaning up previous unstable tags on gitea fork (so nix-update sees only clean semver tags)" mapfile -t PREV_TAGS < <(git ls-remote --tags oleks 'refs/tags/v*-unstable-*' | awk '{print $2}' | sed 's|refs/tags/||;s|\^{}$||' | sort -u) for tag in "${PREV_TAGS[@]}"; do [ -z "$tag" ] && continue log " deleting $tag" git tag -d "$tag" 2>/dev/null || true git push oleks ":refs/tags/$tag" 2>/dev/null || true done # ── 1. nix-update default flow ──────────────────────────────────────────── # Also normalize the in-file version to its bare semver baseline so # nix-update doesn't see a stale unstable suffix from the local file. cd "$FLAKE_HUB" log "Normalizing in-file version baseline" sed -i -E 's/(version = "[^"]+?)-unstable-[0-9]{4}-[0-9]{2}-[0-9]{2}"/\1"/' "$PKG_FILE" log "Running nix-update against oleks/main tip on the gitea fork" nix run nixpkgs#nix-update -- \ --flake gitea-local-fork \ --version=branch=main \ --build # ── 2. Tag gitea fork ───────────────────────────────────────────────────── NEW_REV=$(grep -oP 'rev = "\K[a-f0-9]{40}' "$PKG_FILE" | head -1) NEW_VER=$(grep -oP 'version = "\K[^"]+' "$PKG_FILE" | head -1) TAG="v${NEW_VER}" log "New version: $NEW_VER (rev ${NEW_REV:0:12})" cd "$GITEA_REPO" if git rev-parse --verify --quiet "refs/tags/$TAG" >/dev/null; then log "Tag $TAG already exists locally — skipping" else log "Tagging gitea fork: $TAG at ${NEW_REV:0:12}" git -c commit.gpgsign=false tag -a "$TAG" "$NEW_REV" \ -m "Pinned by nix-customs/flake-hub gitea-local-fork derivation" fi log "Pushing tag to oleks remote" git push oleks "$TAG" 2>/dev/null || log " tag already on remote" # ── 3. Commit + push flake-hub changes ──────────────────────────────────── cd "$FLAKE_HUB" if git diff --quiet -- "$PKG_FILE"; then log "flake-hub: no changes to commit" else log "flake-hub: committing version + hashes bump" git -c commit.gpgsign=false add "$PKG_FILE" git -c commit.gpgsign=false commit -m "gitea-local-fork: refresh to $NEW_VER Pin to gitea fork rev ${NEW_REV:0:12} (tag $TAG). Refreshed by nix-update via passthru.updateScript." fi if git rev-parse '@{u}' >/dev/null 2>&1; then log "flake-hub: pushing" git push else log "flake-hub: no upstream tracking — skipping push" fi log "Done. New version $NEW_VER live at:" log " gitea tag: https://git.oleks.space/oleks/gitea/src/tag/$TAG" log " derivation: $PKG_FILE"