Skip to content

Commit 070325a

Browse files
linw1995Mic92
authored andcommitted
Refresh cached GC root
This helps with tools that delete gcroots based on access time.
1 parent 6dc06d4 commit 070325a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

direnvrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)