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")