Getting Started
Create a binary cache on Cachix and upload a Nix build result so you can reuse it on other machines and in CI.
Create a cache
Section titled “Create a cache”- Sign in to the Cachix dashboard, or create an account if you don’t have one.
- Select New Cache.
- Enter a Unique name using lowercase letters, numbers, and dashes. The name becomes part of your cache’s URL:
https://YOUR-CACHE-NAME.cachix.org. - Choose Public if anyone should be able to download your builds, or Private to restrict downloads to authorized users. Private caches require an active subscription.
- For signing, choose Managed by Cachix. This is the recommended option: Cachix creates the signing key and signs uploaded paths for you. If you need to manage your own key, see self-signed cache configuration.
- Select Create Cache to open your new cache’s dashboard.
Replace MY_CACHE with the name you chose in all commands below.
If you’re setting up caches for several teams or projects, see Organizing your caches.
Install the CLI
Section titled “Install the CLI”Install Nix and the Cachix CLI on the machine you’ll upload builds from.
Authenticate the CLI
Section titled “Authenticate the CLI”Create a token that lets the CLI upload to your new cache:
- Open your cache’s Settings and go to its auth tokens page.
- Enter a description, such as
local development, choose Read and write access, and select an expiration. - Select Create token and copy the token. Cachix shows it only once.
Save the token in your local Cachix configuration, replacing YOUR_TOKEN with the value you copied:
$ cachix authtoken YOUR_TOKENCheck that the CLI can connect and authenticate:
$ cachix doctor --cache MY_CACHEFor CI, supply the token through CACHIX_AUTH_TOKEN instead of saving it locally.
See Authentication for other token options.
Build and push
Section titled “Build and push”Create a directory for a small example build:
$ mkdir cachix-example$ cd cachix-exampleSave the following as default.nix.
It builds a directory containing a greeting:
let pkgs = import <nixpkgs> {};inpkgs.runCommand "hello-cachix" {} '' mkdir -p "$out" echo "Hello from Cachix!" > "$out/message"''Build it and upload the result to your cache:
$ nix-build$ cachix push MY_CACHE ./resultnix-build creates a result symlink to the output in the Nix store.
Cachix follows that link and uploads the result and its runtime dependencies, skipping paths already available from the cache or its upstreams.
A successful push exits with status zero, including when all paths are already available.
Verify the upload
Section titled “Verify the upload”Check that the build result is available:
$ cachix doctor --cache MY_CACHE "$(nix path-info ./result)"Look for found in cache in the store path check.
Use your cache
Section titled “Use your cache”Configure Nix to download builds from your cache:
$ cachix use MY_CACHERun this on each machine that should use the cache.
For private caches, authenticate on those machines first; a read-only token is sufficient for downloads.
Follow any configuration instructions printed by cachix use, or see Use an existing cache for details.
To upload future builds automatically, set up CI. See Pushing to Cachix for other ways to upload builds.