use_nix: file was used in two places and values got confused

Using `file` in the for loop over the `nix_watches` entries
left a value in `file`, so the check '[[ "$file" == ""]]'
always failed.

Found by adding `set -x` to `direnvrc` temporarily and staring
hard at the output.
This commit is contained in:
Eric Wolf 2022-04-03 13:01:14 +02:00 committed by Bryan Bennett
parent a18e37535d
commit 8ce0765b55
No known key found for this signature in database
GPG key ID: EF90E3E98B8F5C0B

View file

@ -166,7 +166,8 @@ use_flake() {
"$HOME/".direnvrc "$HOME/".direnvrc
) )
need_update=0 local need_update=0
local file=
for file in "${nix_watches[@]}"; do for file in "${nix_watches[@]}"; do
if [[ "$file" -nt "$profile_rc" ]]; then if [[ "$file" -nt "$profile_rc" ]]; then
need_update=1 need_update=1
@ -248,7 +249,7 @@ use_nix() {
local attribute= local attribute=
local packages="" local packages=""
local extra_args=() local extra_args=()
local file= local nixfile=
while [[ "$#" -gt 0 ]]; do while [[ "$#" -gt 0 ]]; do
i="$1" i="$1"
shift shift
@ -283,7 +284,7 @@ use_nix() {
if [[ $in_packages == 1 ]]; then if [[ $in_packages == 1 ]]; then
packages+=" $i" packages+=" $i"
else else
file=$i nixfile=$i
fi fi
;; ;;
esac esac
@ -298,6 +299,7 @@ use_nix() {
) )
local need_update=0 local need_update=0
local file=
for file in "${nix_watches[@]}"; do for file in "${nix_watches[@]}"; do
if [[ "$file" -nt "$profile_rc" ]]; then if [[ "$file" -nt "$profile_rc" ]]; then
need_update=1 need_update=1
@ -318,19 +320,19 @@ use_nix() {
extra_args+=("--expr" "with import <nixpkgs> {}; mkShell { buildInputs = [ $packages ]; }") extra_args+=("--expr" "with import <nixpkgs> {}; mkShell { buildInputs = [ $packages ]; }")
else else
# figure out what file we should use # figure out what file we should use
if [[ "$file" == "" ]]; then if [[ "$nixfile" == "" ]]; then
if [[ -e "shell.nix" ]]; then if [[ -e "shell.nix" ]]; then
file="./shell.nix" nixfile="./shell.nix"
elif [[ -e "default.nix" ]]; then elif [[ -e "default.nix" ]]; then
file="./default.nix" nixfile="./default.nix"
fi fi
fi fi
# figure out what attribute we should build # figure out what attribute we should build
if [[ "$attribute" == "" ]]; then if [[ "$attribute" == "" ]]; then
extra_args+=("--file" "$file") extra_args+=("--file" "$nixfile")
else else
extra_args+=("--expr" "(import ${file}).$}attribute}") extra_args+=("--expr" "(import ${nixfile}).$}attribute}")
fi fi
fi fi