You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
0xee 6fb279eca0 Allow calling direnv-cache from subdirectories of $DIRENV_DIR 4 years ago
tests Add tests 4 years ago
LICENSE Initial commit 4 years ago
Makefile Add tests 4 years ago Populate repo with initial version 4 years ago
default.nix Prefer local nix build 4 years ago
direnv-cache Allow calling direnv-cache from subdirectories of $DIRENV_DIR 4 years ago
direnvrc Add tests 4 years ago
shell.nix Add tests 4 years ago



direnv-cache consists of two components: the direnv-cache script and an extension to direnv's stdlib.

To set up direnv-cache, make direnv read the provided direnvrc, eg. via

cp direnvrc ~/.config/direnv/direnvrc

and install direnv-cache somewhere in your PATH.

If you use home-manager, you can add the following to your configuration

    direnv-cache = pkgs.callPackage ./path/to/this/repo {};

home.packages = [ ... direnv-cache ... ];
programs.direnv = {
    enable = true;
    enableBashIntegration = true;
    stdlib = builtins.readFile direnv-cache.direnvrc;


The following assumes a working direnv setup.

Use the cache function in your .envrc files, eg.

cache <<EOF
  # everything in here will be cached
  use nix -p hello

# you can also have stuff outside the cached region
export PATH=/some/other/path:$PATH

If you now enter the directory, direnv will tell you that the environment is not yet cached. We can fix that by running direnv-cache reload. This will also tell direnv to reload. From now on, if you enter the directory, direnv will load the cached environment.

Re-run direnv-cache reload whenever your .envrc or other dependencies change to update the cache.

How it works

Everything piped into the cache function is stored in a recipe file in direnv-cache's cache directory when the .envrc is evaluated. Then, if the environment cache exists, it is sourced.

When direnv-cache reload is called, it looks for a recipe file for the current directory, and runs it. A diff of the environments before and after the recipe is run is written to the directory-specific cache file.