Best practice for caching your nix-shell

I have been enjoying nix-shell for reproducible build-environments; but was not happy at the common wisdom on how to cache the shell in a binary store such as something in Cachix.

The prevailing wisdom outlines a way that ends up caching the whole build-time transitive closure which is way too large.

Here is a much more concise graph for what you need to exactly run your nix-shell

 $ nix-store --query --references $(nix-instantiate shell.nix) | \
    xargs nix-store --realise | \
    xargs nix-store --query --requisites | \
    cachix push your_cache

I wrote a little blog post on the subject as well caching your nix-shell | Farid Zakaria’s Blog


There’s some new development which you can read up

1 Like