Skip to content

feat(infra): nix.moq.dev serves from Backblaze B2 - #9625

Merged
kixelated merged 11 commits into
mainfrom
quest/m0/ci/nix-b2
Nov 25, 2026
Merged

kixelated merged 11 commits into
mainfrom
quest/m0/ci/nix-b2

Conversation

@kixelated

@kixelated kixelated commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

nix.moq.dev's Worker serves the release and CI Nix caches from R2 (nix-moq-dev, nix-ci-moq-dev). The quest nix-b2 moves them to private Backblaze B2 buckets in the us-east-005 account, whose credits cover storage, beside the Rust cache's move (moq-dev/moq#9624).

Approach

  • Worker (infra/nix/src/worker.ts): the R2 bindings become path-style S3 GETs/HEADs to s3.us-east-005.backblazeb2.com/<bucket>/<key>, signed (SigV4) by aws4fetch with each bucket's read-only key, held as the Worker secrets B2_RELEASE_* and B2_CI_*. Release first, then CI, as before. aws4fetch's default 10 retries with backoff are off, so a failed read stays a quick miss.
    • A 5xx, a 429, or a fetch that throws is a miss sent with no-store (logged), so the other bucket can still serve and Nix otherwise builds from source. A 401/403 (a rejected key; the account sets no cap that would also answer 403), a 200 without Content-Length or ETag, or a missing secret throws: a deploy error. Any other answer, such as a 404 or a 400 for a key too long, is a plain cacheable miss.
    • A + in the key is sent as %2B, since aws4fetch signs a path's + as a space and B2 then rejects the signature.
    • The mid-stream body resume from moq-dev/moq#9604 carries over as Range: bytes=<sent>- with If-Match: <first etag>: 206 continues, 412 ends the stream ("object changed"), anything else counts against the same 5-resume cap. New: a body that errors after its last byte closes cleanly instead of resuming into a 416.
  • Writers: just infra nix push, roots, and refresh target B2's S3 endpoint and region; rclone's remote becomes b2: (provider Other). cache.yml reads NIX_B2_CI_* and release-nix.yml reads NIX_B2_RELEASE_* from cache-write. The release copy is backported in moq-dev/moq#9628.
  • Lifecycle (infra/nix/lifecycle.json, now B2's format, keyed by bucket): CI hides objects 14 days after their newest upload; both buckets delete a hidden or superseded version a day later. refresh's copy-onto-itself therefore restarts an object's age, and its old version is gone a day later. just infra nix lifecycle <bucket> applies the file with the B2 CLI and that bucket's write key; create is gone (buckets are made in the console).
  • Docs and quest: infra/README.md's Nix bootstrap describes the B2 buckets, keys, and secrets. The quest is rewritten to what remains after this merges (below).

Done outside the tree

  • B2 buckets nix-moq-dev ("Keep only the last version") and nix-ci-moq-dev (custom: hide after 14 days, delete a day later), both private. Rules confirmed with backblaze-b2 bucket get, applied once more through just infra nix lifecycle.
  • Keys nix-release-read, nix-ci-read (Read Only) in the Worker's B2_RELEASE_* / B2_CI_* secrets on the live Worker (harmless to the R2 code it still runs); nix-release-write, nix-ci-write (Read and Write) in cache-write's NIX_B2_RELEASE_* / NIX_B2_CI_*. Each restricted to its bucket.
  • After moq-dev/moq#9628 merged (cdcc9f2) and with no release-nix.yml run queued or in progress, the R2 token behind NIX_R2_* ("Nix Cache", R2 -> API Tokens) is deleted, so a pre-backport tag fails loudly. A fresh listing of R2 nix-moq-dev then matched the copied one key for key (1,629 objects, size and etag), so the top-up copy had nothing to add and needed no short-lived key.
  • R2 nix-moq-dev's 1,628 cache objects (1.81 GB) copied to B2 through nix.moq.dev; sizes and MD5s match R2's listing for every key (its nix-cache-info is the Worker's, which it answers itself anyway).

Impact

Public API: none. Wire: none. Operational: GitHub secrets NIX_B2_{RELEASE,CI}_* replace NIX_R2_*, and the Worker needs B2_{RELEASE,CI}_*.

Alternatives

  • One key per role for both buckets, as R2's single token: the console scopes a key to one bucket or to all of them, and multi-bucket keys exist only through the API, whose master-key use the maintainer rejected. Per-bucket keys are also narrower.
  • A hand-rolled SigV4 signer: aws4fetch is small, used by Cloudflare's own R2 docs, and signs with WebCrypto.
  • Treating 403 as a miss too: B2 answers 403 both for a bad key and for a hit download cap. Failing loudly surfaces both.
  • Cancelling unfinished large files in the lifecycle: dropped, since the console cannot set it and nix copy does not upload multipart by default.

Decisions

Answered by the maintainer on 2026-11-25 (/quest-run), with the pick to /quest-merge once #9628 landed:

  • ✅ Four keys, read and write per bucket (forced by the console; see Alternatives). The console's Read and Write preset also grants writeBuckets, so a cache-write job could change its bucket's settings, as with mbx's keys.
  • ✅ A 401/403 from B2 fails the request loudly.
  • ✅ The unfinished-large-upload cancel rule is dropped.
  • ✅ just infra nix lifecycle <bucket> stays, run with a short-lived write key for that bucket.

Recorded earlier as recommendations, standing:

  • Bucket names stay nix-moq-dev / nix-ci-moq-dev, so just infra nix push <bucket> call sites are unchanged.
  • The release bucket keeps only the latest version of each object.
  • The backport moves only the writer; release's stale Worker and recipes wait for the next cut.
  • This PR merges with the quest rewritten to what remains (deploy, substitution checks, R2 deletion), since the CI dev-shell check needs cache.yml running from main.

Landing order

moq-dev/moq#9628 merged into release as cdcc9f2, so this can land. After it lands, the Worker deploys once just gh cache-rev reaches this PR's merge, then the substitution checks run and R2 is deleted; the rewritten quest holds these steps.

Validation

  • Real B2, through the new Worker in wrangler dev with the read keys: a narinfo and NAR pushed to nix-ci-moq-dev serve after a release-bucket miss (GET/HEAD 200, Content-Length and cache headers right, NAR bytes hash to the narinfo's FileHash), an absent key 404s cacheably, and nix copy --from the Worker into a scratch store verifies the signature.
  • In a fresh docker.io/nixos/nix container with cache.nixos.org plus that Worker as its only substituters, github:moq-dev/moq/moq-relay-v0.17.18#moq-relay (copied from R2) builds nothing, fetches moq-relay-0.17.18 from the Worker, and prints moq-relay 0.17.18.
  • Writers against real B2 (nixpkgs' Nix 2.35.6, which like CI's has AWS support): just infra nix push nix-ci-moq-dev <path> with a throwaway signing key, roots, and refresh all pass; rclone touch moved the object's upload time from 20:35:40 to 20:35:53 and left the old version for the lifecycle to delete. Test objects removed afterward.
  • Against real B2 through wrangler dev: GET /log/abc-libsigc++-2.drv and a 2000-character key each answer 404 with no exception (signature accepted, refusal a plain miss).
  • infra/nix: bun test, 24 pass. tsc --strict against @cloudflare/workers-types on worker.ts: clean. bun run deploy --dry-run: builds. just check: passes.
  • Not yet: the cutover itself, a tag pushed to B2, and a CI dev shell from main (all after merge).

Follow-ups

None.

Models

  • Size: M
  • Implementer: Claude Code, claude-opus-5-5, unknown

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 9691e64

  • Base: origin/main at 5bb7578

  • Risk: high, A bad change to the Worker's signed B2 reads or the release-nix.yml write path could stop nix.moq.dev from serving released packages to Nix users and downstream flakes that pin old tags, and the diff also changes workflows under .github/workflows/, which the risk file always marks high; reverting the code is quick, but a bad deploy or secret swap reaches those users before a check catches it.

  • Classified: high by Claude Code, claude-haiku-5-5, low effort, session 99ea0355-2cc1-4c21-b91c-ce38b76b2291

  • Reviewer: Codex, gpt-6.2-sol, high effort

  • Session: 01a21472-e67d-7fb2-853f-f09fefef11a4, round 5

  • Score: 10/10, The runbook records the completed release-cache migration steps and keeps the Worker cutover gated on a B2-backed revision selected by Smoke.

  • Rounds: 5; first round 2 (medium 2); findings 2 (medium 2): fixed 2, refuted 0, open 0

  • Findings: none

  • Reviewer: Claude Code, claude-opus-5-5, high effort, second

  • Session: 68a4523a-c6e8-44c2-8f1c-e376259be6b1, round 5

  • Score: 9/10, Since the last round, the branch merged origin/main, which brought the mbx B2 move (#9624) into the README, and added one commit that marks quest steps done (backport merged, R2 write token deleted, B2 listing checked against R2). Nothing in that changes the nix Worker or workflows, and no finding is open.

  • Rounds: 5; first round 2 (medium 2); findings 2 (medium 2): fixed 1, refuted 1, open 0

  • Findings: none

kixelated and others added 2 commits November 25, 2026 11:34
Quest-Claim: 5e4d2a22a82a90f6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title nix.moq.dev serves from Backblaze B2 feat(infra): nix.moq.dev serves from Backblaze B2 Nov 25, 2026
kixelated and others added 2 commits November 25, 2026 12:29
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated and others added 2 commits November 25, 2026 12:49
…cted one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 25, 2026 20:52
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6753de94-642c-4462-a416-ea68057074cb
Commits

Reviewing files that changed from the base of the PR and between 5bb7578 and bb0e176.

Files ignored due to path filters: 1

  • infra/nix/bun.lock is excluded by !**/*.lock
Files selected for processing: 10

  • .github/workflows/cache.yml
  • .github/workflows/release-nix.yml
  • infra/README.md
  • infra/nix/justfile
  • infra/nix/lifecycle.json
  • infra/nix/package.json
  • infra/nix/src/worker.test.ts
  • infra/nix/src/worker.ts
  • infra/nix/wrangler.jsonc
  • quest/m0/ci/nix-b2.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

kixelated and others added 2 commits November 25, 2026 13:06
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… object

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit c9af56c Nov 25, 2026
9 of 10 checks passed
@kixelated
kixelated deleted the quest/m0/ci/nix-b2 branch November 25, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant