How to stop gc from cleaning devshells?

even if i don’t change the inputs of a shell, the garbage collector triggers a rebuild for devshells, is there a way to stop this kinda behaviors

This is one of the nice features of using a tool like nix-direnv. Not only does it add your shells to gcroots, but it automatically enters your devshell whenever you cd into the directory :slight_smile:

Hope that helps.

3 Likes

+1 to nix-direnv, it is an amazing tool for both deshells and traditional shell.nix

nix-direnv is really useful, and several other tools exist to help manage these things.

The most barebones answer to your question, however, is nix-build shell.nix -o shell-gc-root. Just building the result of pkgs.mkShell and registering a gcroot for it will prevent collection.

2 Likes

I’ve just built the devshell in the past and make it exist as result in the same directory and that works.

1 Like

I like to use nix develop --profile ./tools to keep a gc link around.

1 Like