File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,15 @@ _nix_add_gcroot() {
189189 _nix build --out-link " $symlink " " $storepath "
190190}
191191
192+ _nix_refresh_gcroots () {
193+ # Use touch to update all symlinks' timestamps to prevent nh
194+ # from garbage collecting the frequently used direnv environment.
195+ local layout_dir
196+ layout_dir=$( direnv_layout_dir)
197+
198+ touch -h " ${layout_dir} " /flake-profile-* " ${layout_dir} " /flake-inputs/* " ${layout_dir} " /nix-profile-*
199+ }
200+
192201_nix_clean_old_gcroots () {
193202 local layout_dir=$1
194203
@@ -354,6 +363,7 @@ use_flake() {
354363 if [[ -e ${profile_rc} ]]; then
355364 # Our cache is valid, use that
356365 _nix_direnv_info " Using cached dev shell"
366+ _nix_refresh_gcroots
357367 else
358368 # We don't have a profile_rc to use!
359369 _nix_direnv_error " use_flake failed - Is your flake's devShell working?"
@@ -515,6 +525,7 @@ use_nix() {
515525 else
516526 if [[ -e ${profile_rc} ]]; then
517527 _nix_direnv_info " Using cached dev shell"
528+ _nix_refresh_gcroots
518529 else
519530 _nix_direnv_error " use_nix failed - Is your nix shell working?"
520531 unset IN_NIX_SHELL
You can’t perform that action at this time.
0 commit comments