diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 86a0982f3..09b5cecbc 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -102,6 +102,9 @@ std::pair parsePathFlakeRefWithFragment( if (isFlake) { + if (!S_ISDIR(lstat(path).st_mode)) + throw BadURL("path '%s' is not a flake (because it's not a directory)", path); + if (!allowMissing && !pathExists(path + "/flake.nix")){ notice("path '%s' does not contain a 'flake.nix', searching up",path); @@ -124,9 +127,6 @@ std::pair parsePathFlakeRefWithFragment( throw BadURL("could not find a flake.nix file"); } - if (!S_ISDIR(lstat(path).st_mode)) - throw BadURL("path '%s' is not a flake (because it's not a directory)", path); - if (!allowMissing && !pathExists(path + "/flake.nix")) throw BadURL("path '%s' is not a flake (because it doesn't contain a 'flake.nix' file)", path); diff --git a/tests/functional/flakes/search-root.sh b/tests/functional/flakes/search-root.sh index d8586dc8a..6b137aa86 100644 --- a/tests/functional/flakes/search-root.sh +++ b/tests/functional/flakes/search-root.sh @@ -22,7 +22,7 @@ mkdir subdir pushd subdir success=("" . .# .#test ../subdir ../subdir#test "$PWD") -failure=("path:$PWD") +failure=("path:$PWD" "../simple.nix") for i in "${success[@]}"; do nix build $i || fail "flake should be found by searching up directories"