Cached-nix-shell

If you use nix-shell, you probably have noticed that it has quite a long startup time (half a second or even more depending on nix expressions used). It may be annoying or even not suitable for some use-cases.

So, I made cached-nix-shell, a caching layer for nix-shell featuring instant startup time on subsequent runs. The design goal is to make a fast drop-in replacement for nix-shell, including support of shebang scripts and non-interactive commands (i.e. nix-shell --run ...).

Project home: GitHub - xzfc/cached-nix-shell: Instant startup time for nix-shell
Feedback is welcome.

4 Likes

Nice!

I like that you use a LD_PRELOAD hook to trace all the file accesses. Lorri overrides builtins like import and readFile with traces and then scans the evaluation output instead.

Related I also have a pure bash implementation experiment to cache nix builds but could also be used to cache instantiations: https://github.com/zimbatm/nix-experiments/blob/b45e53f67cb9de1dfd96985258f1a0208ba59b70/bin/nix-build-cached

Hopefully one day we’ll have these traces built into nix so that they also work on macOS and other systems that don’t support LD_PRELOAD.

may want to look at direnv+nixify as well, Nix · direnv/direnv Wiki · GitHub

@xzfc - you probably want this GitHub - target/lorri: Your project's nix-env
(I also made own version, but then found lorri, it’s really lot better and it already has been made progress with core nix prople putting their time on it, recommend)

1 Like