Skip to content

Commit

Permalink
Don't fetch from store to store
Browse files Browse the repository at this point in the history
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: NixOS#10627
  • Loading branch information
yshui committed Aug 7, 2024
1 parent 0a167ff commit 13f8cc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/libfetchers/fetch-to-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<fetchers::Cache::Key> cacheKey;

Expand Down
5 changes: 0 additions & 5 deletions tests/functional/flakes/flakes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/<hash1>-<hash2>-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)
Expand Down

0 comments on commit 13f8cc2

Please sign in to comment.