diff options
Diffstat (limited to 'src/libfetchers/fetchers.cc')
-rw-r--r-- | src/libfetchers/fetchers.cc | 20 |
1 files changed, 20 insertions, 0 deletions
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<Tree, Input> Input::fetch(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 (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 == "") |