Skip to content
Cachix

GitHub Actions

During a build, Nix queries the configured caches for missing outputs. In the default daemon mode, the action queues uploads as Nix finishes building paths. In store scan mode, the action checks for paths added during the job and pushes them at the end. See Push modes.

For a repository with a flake that defines a default package, save this workflow as .github/workflows/build.yml. Replace MY_CACHE with your cache name and add a repository secret named CACHIX_AUTH_TOKEN containing a write token for that cache.

name: Build
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: cachix/install-nix-action@v31
- uses: cachix/cachix-action@v17
with:
name: MY_CACHE
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- run: nix build
- uses: cachix/cachix-action@v17
with:
name: MY_CACHE
- uses: cachix/cachix-action@v17
with:
name: MY_CACHE
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- uses: cachix/cachix-action@v17
with:
name: MY_CACHE
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
InputDescriptionRequiredDefault
nameName of the Cachix cache to pull (substitute) from and optionally push to✓
extraPullNamesComma-separated list of additional Cachix cache names to pull (substitute) from
InputDescriptionRequiredDefault
authTokenAuthentication token for Cachix, required for private cache access or to push to any cache
signingKeyPrivate signing key for self-signed caches, used in addition to the auth token to sign store paths
InputDescriptionRequiredDefault
skipPushSet to true to only pull from the cache without pushing any build resultsfalse
useDaemonUse Cachix daemon mode to push store paths as they’re built via post-build hooks. See Push modes for more informationtrue
pathsToPushWhitespace-separated list of specific store paths to push. Leave empty to push all build results
pushFilterRegular expression to exclude derivations from being pushed, for example "(-source$ | nixpkgs\.tar\.gz$)". Ignored if pathsToPush is set. Warning: paths may still be pushed if they are part of another path’s closure
InputDescriptionRequiredDefault
skipAddingSubstituterSet to true to skip adding the cache as a Nix substituterfalse
cachixArgsAdditional command-line arguments to pass to Cachix commands. Defaults to -j8 for parallel processing
cachixBinCustom path to the Cachix binary if not using the default installation
installCommandCustom command to install Cachix instead of the default installation method

The action can push in two modes: daemon mode with post-build hooks and store scan. This can be controlled with the useDaemon option. See Automatic uploads for the CLI workflow.

The daemon registers a post-build hook with Nix. Newly built store paths are pushed to the cache as they’re built. The limitation is that Nix does not trigger the hook for substituted paths.

The store scan method looks for differences in the store at the file system level. It will capture all store paths, including those substituted.

Cachix tokens and signing keys provide full read and/or write access to your caches.

GitHub Actions allows anyone who can edit workflow files to read secrets.

This means developers with write access can read your secrets and access your cache.

Forked pull requests cannot access secrets, so they can only read from public caches.

Malicious code merged from forks can reveal your tokens.