Pushing to Cachix
There are different ways to push store paths to Cachix.
Replace MY_CACHE with your cache name in the examples below.
Store paths and closures
Section titled “Store paths and closures”A build output can refer to other paths in the Nix store.
Together, the output and everything reachable through those references form its runtime closure.
cachix push takes a store path or a symlink such as ./result, walks that closure, and uploads the paths missing from the cache and its upstreams.
Choose what to push
Section titled “Choose what to push”Pushing runtime dependencies
Section titled “Pushing runtime dependencies”$ nix-build | cachix push MY_CACHEPushing build and runtime dependencies
Section titled “Pushing build and runtime dependencies”$ nix-store -qR --include-outputs $(nix-store -qd $(nix-build)) \ | grep -v '\.drv$' \ | cachix push MY_CACHEPushing shell environment
Section titled “Pushing shell environment”$ nix-build shell.nix -A inputDerivation \ | cachix push MY_CACHEPushing whole /nix/store
Section titled “Pushing whole /nix/store”$ nix path-info --all | cachix push MY_CACHEFlakes
Section titled “Flakes”Assuming you’re familiar with Flakes.
Pushing flake inputs
Section titled “Pushing flake inputs”As flake inputs are downloaded from the internet, they can disappear. Copying them over to Cachix saves you from that day.
$ nix flake archive --json \ | jq -r '.path,(.inputs|to_entries[].value.path)' \ | cachix push MY_CACHEPushing runtime closure
Section titled “Pushing runtime closure”To push runtime closure of the default package in a Flake:
$ nix build --no-link --print-out-paths \ | cachix push MY_CACHETo push runtime closure of any set of packages in a Flake:
$ nix build --no-link --print-out-paths .#package-a .#package-b \ | cachix push MY_CACHENote: to build all packages, leave a thumbs up on NixOS/nix#7165.
Pushing shell environment
Section titled “Pushing shell environment”$ nix develop --profile dev-profile -c true$ cachix push MY_CACHE dev-profileAutomatic uploads
Section titled “Automatic uploads”Use watch-store to watch the store continuously or watch-exec to limit observation to the duration of a command.
Pushing all newly built store paths
Section titled “Pushing all newly built store paths”$ cachix watch-store MY_CACHEPush all store paths produced during a command
Section titled “Push all store paths produced during a command”$ cachix watch-exec MY_CACHE -- nix-build --max-jobs 4