GitHub
Nix binary cache playbook

Making a Nix binary cache useful to other people

This playbook is not specific to Ledgeline. Copy it into any flake repo that wants nix run github:you/project to download rather than compile. Substitute your own cache name for <CACHE> and project name for <PROJ>.

Written 2026-08-04 against Cachix + GitHub Actions. Pricing and free-tier terms change, so re-check anything with a number in it.


The two jobs a cache does

A binary cache serves two audiences with opposite characteristics:

CI dependency layerConsumer release artifacts
Sizelarge (often GBs)small (tens of MB)
Churnevery lockfile/toolchain bumponly on release
Downloadsevery CI run, so always warmrare, often cold for weeks
Value if losta slow CI runyour install instructions stop working

Cachix’s free tier garbage-collects least-recently-used. Under LRU the frequently used dependency layer survives and the rarely downloaded release artifact is evicted first, which is the opposite of what you want. LRU deletes the release artifacts first, and the missing paths make a working CI push look broken.


Step 1: work out what consumers resolve to

nix build .#<PROJ> in CI often builds something no user ever installs. List what each user command resolves to:

User commandFlake attribute
nix build github:you/projpackages.<system>.default
nix profile install github:you/projpackages.<system>.default
nix run github:you/projapps.<system>.default (often a different derivation)
nix developdevShells.<system>.default

Check each system separately. A flake that overrides default on darwin (with an .app bundle, for example) has a different graph there than on Linux. Print the evaluated paths rather than reading them off the flake source:

for s in x86_64-linux aarch64-darwin; do
  nix eval --raw ".#packages.$s.default.outPath"; echo
  nix eval --raw ".#apps.$s.default.program"; echo
done

A closure is not everything reachable from the attribute

Nix computes runtime references by scanning build outputs for store-path strings. If a wrapper cps a binary into place rather than symlinking it, the original derivation’s store path is not a reference, and pushing the wrapper does not push the binary. Check it:

outer=$(nix eval --raw .#someWrapper.outPath)
inner=$(nix eval --raw .#theBinary.outPath)
nix path-info -r "$outer" | grep -qF "$inner" \
  && echo "in closure — pushing the wrapper is enough" \
  || echo "NOT in closure — must push it separately"

Name anything that fails that check explicitly when you push and pin.


Step 2: build the consumer artifacts in CI

CI can only push what it built. If packages.default differs by platform, add a platform-guarded build step:

      - name: Build the real distributable
        if: runner.os == 'macOS'
        run: nix build -L --no-link .#macDist

--no-link keeps a previously-created result symlink pointing where later steps expect it.


Step 3: push, filtering out what you don’t need

      - uses: cachix/cachix-action@v17
        with:
          name: <CACHE>
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
          pushFilter: '-(source|vendor)$'

The action’s post-job daemon uploads everything the job built, so put this on every job, not only the build job.

Keep an explicit push step alongside the daemon so reviewers can see what gets pushed, and so you can limit it to push events:

      - name: Push to Cachix
        if: github.event_name == 'push'
        env:
          CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
        run: |
          if [ -z "${CACHIX_AUTH_TOKEN:-}" ]; then
            echo "No CACHIX_AUTH_TOKEN (fork or unset) — skipping cache push."
            exit 0
          fi
          attrs=(.#<PROJ>)
          if [ "$RUNNER_OS" = "macOS" ]; then
            attrs+=(.#macDist .#theBinary)   # per the closure check in Step 1
          fi
          nix build --json "${attrs[@]}" \
            | jq -r '.[].outputs | to_entries[].value' \
            | cachix push <CACHE>

Always check that the token is non-empty. Fork PRs have no secrets, and without the check every outside contributor’s PR fails. Use an if block rather than [ ... ] && attrs+=(...): under bash -e a trailing && whose test fails makes the whole step exit non-zero.


Step 4: pin the consumer artifacts

      - name: Pin release artifacts (exempt from GC)
        if: github.event_name == 'push'
        env:
          CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
        run: |
          if [ -z "${CACHIX_AUTH_TOKEN:-}" ]; then
            echo "No CACHIX_AUTH_TOKEN — skipping pins."
            exit 0
          fi
          sys=$(nix eval --raw --impure --expr builtins.currentSystem)
          cachix pin <CACHE> "<PROJ>-$sys" \
            "$(nix build --no-link --print-out-paths .#<PROJ>)" --keep-revisions 2
cachix pin CACHE-NAME PIN-NAME STORE-PATH [--keep-days N | --keep-revisions N | --keep-forever]

Step 5: tell consumers how to opt in

Pushing alone is not enough. Nix ignores substituters declared in a flake’s nixConfig unless the flake is trusted, so a stranger running your install command builds from source and never knows why.

In the README, either use --accept-flake-config:

nix run --accept-flake-config github:you/project

or give them the permanent form for ~/.config/nix/nix.conf:

extra-substituters = https://<CACHE>.cachix.org
extra-trusted-public-keys = <CACHE>.cachix.org-1:AAAA...

Put this caveat in the README too. substituters is a trusted setting. On a multi-user install, a user not in trusted-users gets ignoring untrusted flake configuration setting 'extra-substituters' and builds from source regardless of which method they used.

A cache is plain signed HTTP, so the Nix implementation does not matter. Determinate Nix, upstream Nix, Lix and nix-darwin all read it the same way. You do not need to push to several caches to support different machines. The one exception is FlakeHub Cache, which requires determinate-nixd login. That requirement also makes it a poor choice for public distribution.


Step 6: verify from outside, without building

Store paths are content-addressed, so evaluating a revision on any machine gives the same paths CI built. You can check coverage in seconds:

REV=github:you/project/<commit-sha>
for s in x86_64-linux aarch64-darwin; do
  p=$(nix eval --raw "$REV#packages.$s.default.outPath")
  code=$(curl -s -o /dev/null -w '%{http_code}' \
    "https://<CACHE>.cachix.org/$(basename "$p" | cut -d- -f1).narinfo")
  echo "$code  $s  $(basename "$p")"
done

200 means a consumer gets a download. 404 means they compile.

To check an entire dependency graph, which catches an unpushed dependency layer:

nix derivation show -r "$REV#packages.x86_64-linux.default" > /tmp/drvs.json
jq -r '.derivations | to_entries[] | select(.key|test("<PROJ>")) | .value.outputs.out.path' /tmp/drvs.json \
  | sort -u | while read -r o; do
      echo "$(curl -s -o /dev/null -w '%{http_code}' \
        "https://<CACHE>.cachix.org/$(basename "$o" | cut -d- -f1).narinfo")  $(basename "$o")"
    done

Reading the result

A 404 for a path CI demonstrably pushed means eviction, not push failure. Before touching the workflow, confirm push is working by grepping a CI log for copying path '...' from 'https://<CACHE>.cachix.org' (a pull proves the round-trip) and for Nothing to push - all store paths are already on Cachix (proves auth). If both appear, the workflow is fine and the problem is retention. Check the cache’s usage and GC page.


When to move off the free tier

Try pins and pushFilter first. For a small project that is usually enough. If you still run out of space, these are the options:

OptionFree tierPublic consumers?Notes
Second Cachix cache for CI churn, public cache as its upstream—✅Avoids double storage. Whether the 5 GB limit is per cache or per account is unverified, so confirm with Cachix.
Garnix$0, 1,500 CI min/mo, no published cap, ~3mo retention✅ no auth for public reposCI + cache in one. Darwin is opt-in. The default build set is Linux-only.
Cloudflare R210 GB, $0 egress✅~$0/mo at small scale. Needs a custom domain (r2.dev rate-limits), and you must upload nix-cache-info yourself, because nix copy writes only StoreDir. You own GC.
Attic (self-hosted)free software✅Still 0.1.0 with no releases, and maintenance is patchy. You run and maintain the server.
FlakeHub Cachenone⚠️ requires loginBreaks anonymous nix run.
cache-nix-action / magic-nix-cacheGHA cache, 10 GB/repo❌ impossibleNeeds a per-job token and has no anonymous endpoint, so it only works inside CI. GitHub Free cannot buy more than 10 GB.

Checklist