Go to file
0xee 6fb279eca0 Allow calling direnv-cache from subdirectories of $DIRENV_DIR 2020-02-03 11:33:25 +01:00
tests Add tests 2019-12-03 20:43:28 +01:00
LICENSE Initial commit 2019-11-19 14:42:52 +01:00
Makefile Add tests 2019-12-03 20:43:28 +01:00
README.md Populate repo with initial version 2019-11-20 10:09:15 +01:00
default.nix Prefer local nix build 2020-01-23 09:54:42 +01:00
direnv-cache Allow calling direnv-cache from subdirectories of $DIRENV_DIR 2020-02-03 11:33:25 +01:00
direnvrc Add tests 2019-12-03 20:43:28 +01:00
shell.nix Add tests 2019-12-03 20:43:28 +01:00




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.