From 13f8cc240a32d059ed939263eea4cd7f3e4aa0a4 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 7 Aug 2024 15:52:48 +0100 Subject: [PATCH] Don't fetch from store to store If the source path for fetchToStore is a direct store path, (i.e. /nix/store/hash-name. things like /nix/store/hash-name/file.sh does not count), return it directly instead of copying it. Related: #10627 --- src/libfetchers/fetch-to-store.cc | 11 +++++++++++ tests/functional/flakes/flakes.sh | 5 ----- 2 files changed, 11 insertions(+), 5 deletions(-) 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)