Skip to content

Commit

Permalink
Input::fetchToStore(): Don't try to substitute
Browse files Browse the repository at this point in the history
Having a narHash doesn't mean that we have the other attributes
returned by the fetcher (such as lastModified or rev). For instance,

   $ nix flake metadata github:NixOS/patchelf/7c2f768bf9601268a4e71c2ebe91e2011918a70f
   Last modified: 2024-01-15 10:51:22

but

   $ nix flake metadata github:NixOS/patchelf/7c2f768bf9601268a4e71c2ebe91e2011918a70f?narHash=sha256-PPXqKY2hJng4DBVE0I4xshv/vGLUskL7jl53roB8UdU%3D
   (does not print a "Last modified")

The latter only happens if the store path already exists or is
substitutable, which made this impure behaviour unpredictable.

Fixes NixOS#10601.
  • Loading branch information
edolstra committed Apr 26, 2024
1 parent 84e0c46 commit a1920a0
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,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

0 comments on commit a1920a0

Please sign in to comment.