diff --git a/src/libfetchers/fetch-to-store.cc b/src/libfetchers/fetch-to-store.cc index 65aa72a6c36a..f7f4aed4d8d3 100644 --- a/src/libfetchers/fetch-to-store.cc +++ b/src/libfetchers/fetch-to-store.cc @@ -15,6 +15,17 @@ StorePath fetchToStore( { // FIXME: add an optimisation for the case where the accessor is // a `PosixSourceAccessor` pointing to a store path. + if (store.isInStore(path.path.abs()) && !filter) { + auto storePath = store.toStorePath(path.path.abs()); + if (storePath.second == "") { + debug( + "source path '%s' is already in the store: '%s', '%s'", + path, + store.printStorePath(storePath.first), + storePath.second); + return storePath.first; + } + } std::optional cacheKey; diff --git a/tests/functional/flakes/flakes.sh b/tests/functional/flakes/flakes.sh index 26b91eda751a..461a3c2e4a29 100755 --- a/tests/functional/flakes/flakes.sh +++ b/tests/functional/flakes/flakes.sh @@ -246,11 +246,6 @@ nix build -o "$TEST_ROOT/result" --expr "(builtins.getFlake \"git+file://$flake1 # Regression test for baseNameOf on the root of the flake. [[ $(nix eval --raw flake1#baseName) =~ ^[a-z0-9]+-source$ ]] -# Test that the root of a tree returns a path named /nix/store/--source. -# This behavior is *not* desired, but has existed for a while. -# Issue #10627 what to do about it. -[[ $(nix eval --raw flake1#root) =~ ^.*/[a-z0-9]+-[a-z0-9]+-source$ ]] - # Building a flake with an unlocked dependency should fail in pure mode. (! nix build -o "$TEST_ROOT/result" flake2#bar --no-registries) (! nix build -o "$TEST_ROOT/result" flake2#bar --no-use-registries)