Log what causes the cache to be invalidated

Fixes https://github.com/nix-community/nix-direnv/issues/597

Co-authored-by: Bryan Bennett <Bryan.Bennett@proton.me>
This commit is contained in:
Winter M 2025-10-20 16:48:52 -04:00
parent 6dc06d41bc
commit d37e01a6d5

View file

@ -293,21 +293,38 @@ use_flake() {
local profile_rc="${profile}.rc" local profile_rc="${profile}.rc"
local flake_inputs="${layout_dir}/flake-inputs/" local flake_inputs="${layout_dir}/flake-inputs/"
local need_update=0
local watches local watches
_nix_direnv_watches watches _nix_direnv_watches watches
local profile_missing=0
if [[ ! -e $profile ]]; then
_nix_direnv_info "cache invalidated: profile ($profile) does not exist"
profile_missing=1
fi
local profile_rc_missing=0
if [[ ! -e $profile_rc ]]; then
_nix_direnv_info "cache invalidated: profile_rc ($profile_rc) does not exist"
profile_rc_missing=1
fi
local file_nt_profilerc=0
local file= local file=
local newer_files
for file in "${watches[@]}"; do for file in "${watches[@]}"; do
if [[ $file -nt $profile_rc ]]; then if [[ $file -nt $profile_rc ]]; then
need_update=1 newer_files+=("$file")
break file_nt_profilerc=1
fi fi
done done
if [[ ! -e $profile || if [[ $file_nt_profilerc -eq 1 ]]; then
! -e $profile_rc || _nix_direnv_info "cache invalidated: files newer than cache:"
$need_update -eq 1 ]] \ echo -n "$_NIX_DIRENV_LOG_PREFIX" >/dev/stderr
; then printf "%s\n" "${newer_files[@]}" >/dev/stderr
fi
if [[ $profile_missing -eq 1 || $profile_rc_missing -eq 1 || $file_nt_profilerc -eq 1 ]]; then
if [[ $_nix_direnv_manual_reload -eq 1 && -z ${_nix_direnv_force_reload-} ]]; then if [[ $_nix_direnv_manual_reload -eq 1 && -z ${_nix_direnv_force_reload-} ]]; then
_nix_direnv_warn_manual_reload "$profile_rc" _nix_direnv_warn_manual_reload "$profile_rc"
@ -457,21 +474,38 @@ use_nix() {
watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" "shell.nix" "default.nix" watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" "shell.nix" "default.nix"
local need_update=0
local watches local watches
_nix_direnv_watches watches _nix_direnv_watches watches
local profile_missing=0
if [[ ! -e $profile ]]; then
_nix_direnv_info "cache invalidated: profile ($profile) does not exist"
profile_missing=1
fi
local profile_rc_missing=0
if [[ ! -e $profile_rc ]]; then
_nix_direnv_info "cache invalidated: profile_rc ($profile_rc) does not exist"
profile_rc_missing=1
fi
local file_nt_profilerc=0
local file= local file=
local newer_files
for file in "${watches[@]}"; do for file in "${watches[@]}"; do
if [[ $file -nt $profile_rc ]]; then if [[ $file -nt $profile_rc ]]; then
need_update=1 newer_files+=("$file")
break file_nt_profilerc=1
fi fi
done done
if [[ ! -e $profile || if [[ $file_nt_profilerc -eq 1 ]]; then
! -e $profile_rc || _nix_direnv_info "cache invalidated: files newer than cache:"
$need_update -eq 1 ]] \ echo -n "$_NIX_DIRENV_LOG_PREFIX" >/dev/stderr
; then printf "%s\n" "${newer_files[@]}" >/dev/stderr
fi
if [[ $profile_missing -eq 1 || $profile_rc_missing -eq 1 || $file_nt_profilerc -eq 1 ]]; then
if [[ $_nix_direnv_manual_reload -eq 1 && -z ${_nix_direnv_force_reload-} ]]; then if [[ $_nix_direnv_manual_reload -eq 1 && -z ${_nix_direnv_force_reload-} ]]; then
_nix_direnv_warn_manual_reload "$profile_rc" _nix_direnv_warn_manual_reload "$profile_rc"
else else