From ba0cbc1c071388c1f31b0624b83cda6048128423 Mon Sep 17 00:00:00 2001 From: Bryan Bennett Date: Mon, 13 Jun 2022 09:34:41 -0400 Subject: [PATCH] Watch nixfile in use_nix This allows us to track the entry point the user specified or whatever entry point we fallback to via auto-selection. This should suprise fewer users. Closes #197 --- direnvrc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/direnvrc b/direnvrc index 33c5c32..754bbc8 100644 --- a/direnvrc +++ b/direnvrc @@ -249,7 +249,14 @@ use_nix() { local attribute= local packages="" local extra_args=() + local nixfile= + if [[ -e "shell.nix" ]]; then + nixfile="./shell.nix" + elif [[ -e "default.nix" ]]; then + nixfile="./default.nix" + fi + while [[ "$#" -gt 0 ]]; do i="$1" shift @@ -295,7 +302,9 @@ use_nix() { esac done - nix_direnv_watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" .envrc default.nix shell.nix + # nixfile may be empty, + # but nix_direnv_watch_file checks for existance before adding to watches + nix_direnv_watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" .envrc "$nixfile" local need_update=0 local file= @@ -317,15 +326,6 @@ use_nix() { if [[ "$packages" != "" ]]; then extra_args+=("--expr" "with import {}; mkShell { buildInputs = [ $packages ]; }") else - # figure out what file we should use - if [[ "$nixfile" == "" ]]; then - if [[ -e "shell.nix" ]]; then - nixfile="./shell.nix" - elif [[ -e "default.nix" ]]; then - nixfile="./default.nix" - fi - fi - # figure out what attribute we should build if [[ "$attribute" == "" ]]; then extra_args+=("--file" "$nixfile")