mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 14:52:55 +00:00
Input::fetchToStore(): Don't try to substitute
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 #10601.
This commit is contained in:
parent
84e0c464f1
commit
ff107d9d03
@ -167,24 +167,6 @@ std::pair<StorePath, Input> Input::fetchToStore(ref<Store> store) const
|
|||||||
if (!scheme)
|
if (!scheme)
|
||||||
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
|
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> {
|
auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
|
||||||
try {
|
try {
|
||||||
auto [accessor, final] = getAccessorUnchecked(store);
|
auto [accessor, final] = getAccessorUnchecked(store);
|
||||||
|
@ -33,9 +33,6 @@ test_tarball() {
|
|||||||
nix-build -o $TEST_ROOT/result -E "import (fetchTree file://$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; })"
|
||||||
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })"
|
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 ]]
|
[[ $(nix eval --impure --expr "(fetchTree file://$tarball).lastModified") = 1000000000 ]]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user