diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 9741d98c5..54282d40f 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -52,36 +52,6 @@ static std::tuple fetchOrSubstituteTree( bool allowLookup, FlakeCache & flakeCache) { - /* 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 (originalRef.input.isDirect() && originalRef.input.isImmutable() && originalRef.input.hasAllInfo()) { - try { - auto storePath = originalRef.input.computeStorePath(*state.store); - - state.store->ensurePath(storePath); - - debug("using substituted/cached input '%s' in '%s'", - originalRef, state.store->printStorePath(storePath)); - - auto actualPath = state.store->toRealPath(storePath); - - if (state.allowedPaths) - state.allowedPaths->insert(actualPath); - - return { - Tree { - .actualPath = actualPath, - .storePath = std::move(storePath), - }, - originalRef, - originalRef - }; - } catch (Error & e) { - debug("substitution of input '%s' failed: %s", originalRef, e.what()); - } - } - auto resolvedRef = lookupInFlakeCache(flakeCache, maybeLookupFlake(state.store, lookupInFlakeCache(flakeCache, originalRef), allowLookup)); diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index a1ad0a7b9..28f9cdb31 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -88,31 +88,6 @@ static void prim_fetchTree(EvalState & state, const Pos & pos, Value * * args, V if (evalSettings.pureEval && !input.isImmutable()) throw Error("in pure evaluation mode, 'fetchTree' requires an immutable input, at %s", pos); - /* 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 (input.hasAllInfo()) { - auto storePath = input.computeStorePath(*state.store); - - try { - state.store->ensurePath(storePath); - - debug("using substituted/cached input '%s' in '%s'", - input.to_string(), state.store->printStorePath(storePath)); - - auto actualPath = state.store->toRealPath(storePath); - - if (state.allowedPaths) - state.allowedPaths->insert(actualPath); - - emitTreeAttrs(state, fetchers::Tree { .actualPath = actualPath, .storePath = std::move(storePath) }, input, v); - - return; - } catch (Error & e) { - debug("substitution of input '%s' failed: %s", input.to_string(), e.what()); - } - } - auto [tree, input2] = input.fetch(state.store); if (state.allowedPaths) diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index aac8aa8c5..f0d8f72c8 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -103,6 +103,26 @@ std::pair Input::fetch(ref 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 (hasAllInfo()) { + try { + auto storePath = computeStorePath(*store); + + store->ensurePath(storePath); + + debug("using substituted/cached input '%s' in '%s'", + to_string(), store->printStorePath(storePath)); + + auto actualPath = store->toRealPath(storePath); + + return {fetchers::Tree { .actualPath = actualPath, .storePath = std::move(storePath) }, *this}; + } catch (Error & e) { + debug("substitution of input '%s' failed: %s", to_string(), e.what()); + } + } + auto [tree, input] = scheme->fetch(store, *this); if (tree.actualPath == "")