Skip to content

Commit

Permalink
Merge pull request #10612 from edolstra/no-flake-substitution
Browse files Browse the repository at this point in the history
Input::fetchToStore(): Don't try to substitute
  • Loading branch information
edolstra authored Sep 16, 2024
2 parents 2c42a9d + 12fd65d commit 176334d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
8 changes: 8 additions & 0 deletions doc/manual/rl-next/no-flake-substitution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
synopsis: Flakes are no longer substituted
prs: [10612]
---

Nix will no longer attempt to substitute the source code of flakes from a binary cache. This functionality was broken because it could lead to different evaluation results depending on whether the flake was available in the binary cache, or even depending on whether the flake was already in the local store.

Author: [**@edolstra**](https://github.com/edolstra)
18 changes: 0 additions & 18 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,6 @@ std::pair<StorePath, Input> Input::fetchToStore(ref<Store> store) const
if (!scheme)
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));

/* The tree may already be in the Nix store, or it could be
substituted (which is often faster than fetching from the
original source). So check that. */
if (getNarHash()) {
try {
auto storePath = computeStorePath(*store);

store->ensurePath(storePath);

debug("using substituted/cached input '%s' in '%s'",
to_string(), store->printStorePath(storePath));

return {std::move(storePath), *this};
} catch (Error & e) {
debug("substitution of input '%s' failed: %s", to_string(), e.what());
}
}

auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
try {
auto [accessor, final] = getAccessorUnchecked(store);
Expand Down
5 changes: 3 additions & 2 deletions src/libflake/flake/lockfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ StorePath LockedNode::computeStorePath(Store & store) const
}


static std::shared_ptr<Node> doFind(const ref<Node>& root, const InputPath & path, std::vector<InputPath>& visited) {
static std::shared_ptr<Node> doFind(const ref<Node> & root, const InputPath & path, std::vector<InputPath> & visited)
{
auto pos = root;

auto found = std::find(visited.cbegin(), visited.cend(), path);

if(found != visited.end()) {
if (found != visited.end()) {
std::vector<std::string> cycle;
std::transform(found, visited.cend(), std::back_inserter(cycle), printInputPath);
cycle.push_back(printInputPath(path));
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/flakes/follow-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

source ./common.sh

# FIXME: this test is disabled because relative path flakes are broken. Re-enable this in #10089.
exit 0

requireGit

flakeFollowsA=$TEST_ROOT/follows/flakeA
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ test_tarball() {
nix-build -o "$TEST_ROOT"/result -E "import (fetchTree file://$tarball)"
nix-build -o "$TEST_ROOT"/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; })"
nix-build -o "$TEST_ROOT"/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })"
# Do not re-fetch paths already present
nix-build -o "$TEST_ROOT"/result -E "import (fetchTree { type = \"tarball\"; url = file:///does-not-exist/must-remain-unused/$tarball; narHash = \"$hash\"; })"
expectStderr 102 nix-build -o "$TEST_ROOT"/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"sha256-xdKv2pq/IiwLSnBBJXW8hNowI4MrdZfW+SYqDQs7Tzc=\"; })" | grep 'NAR hash mismatch in input'

[[ $(nix eval --impure --expr "(fetchTree file://$tarball).lastModified") = 1000000000 ]]

Expand Down
6 changes: 6 additions & 0 deletions tests/nixos/github-flakes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,14 @@ in
print(out)
info = json.loads(out)
assert info["revision"] == "${private-flake-rev}", f"revision mismatch: {info['revision']} != ${private-flake-rev}"
assert info["fingerprint"]
cat_log()
# Fetching with the resolved URL should produce the same result.
info2 = json.loads(client.succeed(f"nix flake metadata {info['url']} --json --access-tokens github.com=ghp_000000000000000000000000000000000000 --tarball-ttl 0"))
print(info["fingerprint"], info2["fingerprint"])
assert info["fingerprint"] == info2["fingerprint"], "fingerprint mismatch"
client.succeed("nix registry pin nixpkgs")
client.succeed("nix flake metadata nixpkgs --tarball-ttl 0 >&2")
Expand Down

0 comments on commit 176334d

Please sign in to comment.