From 070325a12625a7c7aa29aa0f6b155ac8bf0b531c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=AE=20=28Jade=20Lin=29?= Date: Fri, 24 Oct 2025 17:54:09 +0800 Subject: [PATCH] Refresh cached GC root This helps with tools that delete gcroots based on access time. --- direnvrc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/direnvrc b/direnvrc index c68edf6..96e5f77 100644 --- a/direnvrc +++ b/direnvrc @@ -189,6 +189,15 @@ _nix_add_gcroot() { _nix build --out-link "$symlink" "$storepath" } +_nix_refresh_gcroots() { + # Use touch to update all symlinks' timestamps to prevent nh + # from garbage collecting the frequently used direnv environment. + local layout_dir + layout_dir=$(direnv_layout_dir) + + touch -h "${layout_dir}"/flake-profile-* "${layout_dir}"/flake-inputs/* "${layout_dir}"/nix-profile-* +} + _nix_clean_old_gcroots() { local layout_dir=$1 @@ -354,6 +363,7 @@ use_flake() { if [[ -e ${profile_rc} ]]; then # Our cache is valid, use that _nix_direnv_info "Using cached dev shell" + _nix_refresh_gcroots else # We don't have a profile_rc to use! _nix_direnv_error "use_flake failed - Is your flake's devShell working?" @@ -515,6 +525,7 @@ use_nix() { else if [[ -e ${profile_rc} ]]; then _nix_direnv_info "Using cached dev shell" + _nix_refresh_gcroots else _nix_direnv_error "use_nix failed - Is your nix shell working?" unset IN_NIX_SHELL