bitspire/deploy/push-cache.sh
Padreug f589b1c078 fix(deploy/push-cache): push build-time deps too, not just runtime closure
cachix push by default only walks the RUNTIME closure of the paths it
gets on stdin. Build-time inputs like fetchPnpmDeps tarballs are
consumed during a build and then thrown away — never referenced from
the final output — so they never make it into the cache.

This bites when an ATM has the cached runtime output for an older
version of bitspire-atm-app but then needs to rebuild it (e.g. because
a flake.nix change shifts the toplevel hash, cascading through to a
new app derivation). Sintra OOM-killed itself today (2026-05-25) doing
exactly this: 1.4 GB of pnpm install + node-headers on 1 GB of RAM.

Fix: query the .drv that produced each output path, then walk
`nix-store -qR --include-outputs <drv>` — that gives the full
build-time closure (every path needed to realize the build, including
fixed-output fetchers like fetchPnpmDeps). cachix push then uploads
all of them.

Cost: somewhat larger pushes, but the dev box has the headroom.
Benefit: ATM nixos-upgrade never falls into the rebuild-from-source
trap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-01 19:12:11 +02:00

88 lines
3.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build the douro-installed system closure and push all paths to cachix.
#
# Run from your dev machine (Arch) after pushing code to the repo.
# Requires: nix (Determinate), cachix (authenticated via ~/.config/cachix/cachix.dhall)
#
# Usage:
# ./deploy/push-cache.sh # build + push douro-installed (default)
# ./deploy/push-cache.sh sintra # build + push sintra-installed toplevel
# ./deploy/push-cache.sh batm3 # build + push batm3-installed toplevel
# ./deploy/push-cache.sh douro-live # push the live-ISO variant (one-off flash use)
# ./deploy/push-cache.sh sintra-live # same, for sintra
# ./deploy/push-cache.sh tejo # tejo currently lives in iso form only
# ./deploy/push-cache.sh all # build + push every installed + live target
#
# Bare `<model>` targets push the INSTALLED system the auto-upgrade pulls
# from `?ref=<branch>#<model>-installed`. `<model>-live` targets push the
# bootable ISO, used only for fresh USB-flashed installs.
set -euo pipefail
CACHE="aiolabs"
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$SCRIPT_DIR"
target="${1:-douro}"
build_and_push() {
local name="$1"
local attr="$2"
echo "==> Building $name ($attr)..."
local out_paths
out_paths=$(nix build ".#$attr" --no-link --print-out-paths)
# Walk the BUILD-TIME closure (not just runtime) so derivations like
# `bitspire-atm-app-pnpm-deps` (fetchPnpmDeps tarball, consumed only
# during the app's build and discarded) land in the cache. Without
# this, ATMs that need to rebuild the app from source — i.e. any time
# `cachix push` already-cached the runtime output but a downstream
# eval needs a new toplevel that re-derives the app — would OOM-kill
# themselves trying to run `pnpm install` locally on 1 GB of RAM.
# OOM caught on Sintra 2026-05-25 with the 1.4 GB pnpm-deps build.
local drvs
drvs=$(echo "$out_paths" | xargs -r -n1 nix-store -q --deriver)
echo "$drvs" | xargs -r nix-store -qR --include-outputs | cachix push "$CACHE"
echo "==> Pushed $name (runtime + build-time closure) to $CACHE.cachix.org"
}
case "$target" in
douro)
build_and_push "douro-installed toplevel" "nixosConfigurations.douro-installed.config.system.build.toplevel"
;;
douro-live)
build_and_push "douro live ISO" "iso-douro"
;;
tejo)
build_and_push "tejo live ISO" "iso-tejo"
;;
sintra)
build_and_push "sintra-installed toplevel" "nixosConfigurations.sintra-installed.config.system.build.toplevel"
;;
sintra-live)
build_and_push "sintra live ISO" "iso-sintra"
;;
batm3)
build_and_push "batm3-installed toplevel" "nixosConfigurations.batm3-installed.config.system.build.toplevel"
;;
batm3-live)
build_and_push "batm3 live ISO" "iso-batm3"
;;
all)
build_and_push "douro-installed toplevel" "nixosConfigurations.douro-installed.config.system.build.toplevel"
build_and_push "sintra-installed toplevel" "nixosConfigurations.sintra-installed.config.system.build.toplevel"
build_and_push "batm3-installed toplevel" "nixosConfigurations.batm3-installed.config.system.build.toplevel"
build_and_push "douro live ISO" "iso-douro"
build_and_push "tejo live ISO" "iso-tejo"
build_and_push "sintra live ISO" "iso-sintra"
build_and_push "batm3 live ISO" "iso-batm3"
;;
*)
echo "Usage: $0 [douro|douro-live|tejo|sintra|sintra-live|batm3|batm3-live|all]"
exit 1
;;
esac
echo ""
echo "Done. ATMs will pull binaries from https://$CACHE.cachix.org on next upgrade."