git.iko.soy/typeable/nix-s3-cache-action
on anisimoffnikita/speed-up help sign in
git clone ssh://git.iko.soy/typeable/nix-s3-cache-action

Nix S3 cache action

Composite GitHub Action for recording Nix build output paths and uploading them to an S3-backed binary cache.

Usage

- name: Enable Nix remote cache path recorder
  uses: typeable/nix-s3-cache-action@v1
  with:
    operation: enable-recorder

- name: Upload built Nix paths to S3 cache
  if: always()
  uses: typeable/nix-s3-cache-action@v1
  with:
    operation: upload
    aws-role-to-assume: ${{ secrets.AWS_NIX_CACHE_IAM_ROLE }}
    aws-region: us-east-1
    role-duration-seconds: 21600
    cache-private-key: ${{ secrets.NIX_CACHE_PRIVATE_KEY }}
    cache-s3-store-url: ${{ vars.NIX_CACHE_S3_STORE_URL }}

Inputs

NameRequiredDefaultDescription
operationyesOperation to run: enable-recorder or upload.
aws-role-to-assumenoAWS IAM role to assume before uploading Nix paths.
aws-regionnous-east-1AWS region for the Nix cache upload role.
role-duration-secondsno21600AWS role duration for the Nix cache upload role.
cache-private-keynoPrivate signing key for the Nix binary cache.
cache-s3-store-urlnoNix S3 store URL used as the nix copy destination.
cache-query-jobsno16Parallel cache metadata queries, from 1 to 128. Set to 1 to disable metadata prefetch and use Nix's native concurrency.

Before uploading, the action resolves the recorded paths' full dependency closure and checks S3 metadata in parallel. These checks populate Nix's shared on-disk narinfo cache, so the subsequent nix copy can reuse the results. Missing paths are expected; other query errors fail the action. The copy remains recursive and uploads dependencies before their dependents.

This helps when the runner has few CPU cores and S3 request latency dominates: Nix 2.24 limits its native S3 metadata query pool to the number of CPU cores. parallel-compression=true only parallelizes compression, not these queries. The action logs closure resolution, metadata query batches, and copy durations.

To tune the metadata concurrency, add cache-query-jobs: "32" to the upload step's with block. More workers use more memory and S3 connections; they do not change the number of concurrent NAR uploads within nix copy.