Skip to content

Instantly share code, notes, and snippets.

View wuz's full-sized avatar

Conlin Durbin wuz

View GitHub Profile
@mbbx6spp
mbbx6spp / .00readme.org
Last active August 22, 2023 02:42
A caching and persistent Nix shell with direnv

Cached and Persistent Nix shell with direnv integration

Problem being solved

  • the default direnv Nix integration from projects loads a Nix shell every new terminal or every time shell.nix and/or default.nix changes. On larger projects with a lot of Nix shell dependencies, that can cause the terminal to take more than 6 seconds to load, which significantly degrades the developer experience (DX).
  • when a developer garbage collects in their Nix store, often the Nix shell dependencies are deleted also which causes a slow start the next time the project’s Nix shell is requested, also degrading developer experience (DX).

Solution outline

  • on first Nix shell load, the Nix shell is evaluated fully such that direnv dumps the environment from the spawn Nix shell process