diff --git a/overlays/mods/update.sh b/overlays/mods/update.sh index 41df3be..363bc19 100755 --- a/overlays/mods/update.sh +++ b/overlays/mods/update.sh @@ -71,8 +71,11 @@ TAG_PREFIX="n8n@" # ── 1. Latest stable release ─────────────────────────────────────────────── echo "Fetching latest stable release of $REPO ..." +# `|| true` keeps `set -euo pipefail` from killing the script inside the +# substitution on curl/jq failure (e.g. network down) — the empty-value +# check below then produces the actual error message. LATEST_TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | - jq -r 'select(.prerelease == false) | .tag_name') + jq -r 'select(.prerelease == false) | .tag_name' || true) if [[ -z "$LATEST_TAG" ]]; then echo "ERROR: No stable release found for $REPO" >&2 @@ -114,8 +117,14 @@ sed -i "s|^\([[:space:]]*\)version = \"[^\"]*\";|\1version = \"$VERSION\";|" "$N echo "==> Computing src hash ..." SRC_URL="https://github.com/$REPO/archive/refs/tags/${TAG_PREFIX}${VERSION}.tar.gz" # `--name n8n-source` works around the `@` in the upstream tag name -# (nix-prefetch-url refuses filenames containing `@`). -SRC_HASH=$(nix-prefetch-url --unpack --type sha256 --name n8n-source "$SRC_URL" 2>/dev/null) +# (nix-prefetch-url refuses filenames containing `@`). `|| true` + guard so a +# prefetch failure (network, rate limit, vanished tag) prints an error instead +# of dying silently under `set -e` (stderr is discarded on purpose above). +SRC_HASH=$(nix-prefetch-url --unpack --type sha256 --name n8n-source "$SRC_URL" 2>/dev/null || true) +if [[ -z "$SRC_HASH" ]]; then + echo "ERROR: nix-prefetch-url could not fetch/hash $SRC_URL" >&2 + exit 1 +fi SRC_SRI=$(nix hash convert --hash-algo sha256 --to sri "$SRC_HASH") echo " src hash: $SRC_SRI" @@ -155,10 +164,15 @@ BUILD_OUTPUT=$(nix build --impure --no-link --expr "$NIX_EXPR" 2>&1 || true) # "specified"/"Expected" and the correct one as "got:"/"Got:". Different nix # versions label/capitalise differently, so filter out the sentinel and take # whatever real sha256 remains. +# +# The trailing `|| true` is load-bearing: with `set -euo pipefail` a pipeline +# like `grep -oE | grep -v | tail` returns non-zero when NO hash is present +# (grep finds nothing / grep -v filters everything), which used to abort the +# script right here — silently, before the diagnostics below could run. PNPM_HASH=$(echo "$BUILD_OUTPUT" | grep -oE 'sha256-[A-Za-z0-9+/=]+' | grep -v 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | - tail -1) + tail -1 || true) if [[ -z "$PNPM_HASH" ]]; then echo "ERROR: could not extract a pnpmDeps hash from the build output." >&2 @@ -170,6 +184,12 @@ if [[ -z "$PNPM_HASH" ]]; then echo " Cause: the pinned pnpm cannot parse upstream's pnpm-lock.yaml" >&2 echo " anymore (lockfile serialisation changed across pnpm majors)." >&2 echo " Bump the pnpm major and fetcherVersion in $NIX_FILE." >&2 + elif grep -q 'ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY' <<<"$BUILD_OUTPUT"; then + echo " Cause: the pinned pnpm cannot resolve upstream's pnpm-lock.yaml" >&2 + echo " (upstream serialises newer lockfile constructs, e.g. patched-" >&2 + echo " dependency patch_hash keys, that this pnpm major mishandles)." >&2 + echo " Bump the pnpm major in $NIX_FILE (fetchPnpmDeps AND the" >&2 + echo " nativeBuildInputs swap threshold)." >&2 else echo " This usually means fetchPnpmDeps failed for a reason OTHER than" >&2 echo " a hash mismatch (e.g. a pnpm-lock patch in n8n.nix no longer applies," >&2