Go to file
0xee c767762ee0 Always recreate recipe by evaluating .envrc
evaluating .envrc (not the cached section) should not be expensive
2019-12-16 14:56:19 +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 Add tests 2019-12-03 20:43:28 +01:00
direnv-cache Always recreate recipe by evaluating .envrc 2019-12-16 14:56:19 +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

README.md

direnv-cache

Setup

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

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

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

Usage

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
EOF

# 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.