Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions direnvrc
Original file line number Diff line number Diff line change
Expand Up @@ -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-*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified it further.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets at the heart of what I was trying to point out earlier. I wish we had a directory or namespace to select only "our" files, but checking to see if these files exist here is redundant, as the globs proved they do (+/- a race condition, which I refuse to admit is a problem here until I am proven wrong).

The fact that our files aren't isolated is not this PR's problem however and I might find time to introduce that change at some point in the near future.

}

_nix_clean_old_gcroots() {
local layout_dir=$1

Expand Down Expand Up @@ -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?"
Expand Down Expand Up @@ -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
Expand Down
Loading