Skip to content

Comments

Try to substitute builtins.fetch*#3721

Closed
matthewbauer wants to merge 1 commit intoNixOS:masterfrom
matthewbauer:substitute-fetchers
Closed

Try to substitute builtins.fetch*#3721
matthewbauer wants to merge 1 commit intoNixOS:masterfrom
matthewbauer:substitute-fetchers

Conversation

@matthewbauer
Copy link
Member

builtins.fetch* aren’t technically derivations, so they never got
substituted. To work around this, we can try to substitute this store
path during evaluation. This can happen any time a hash is provided.

builtins.fetch* aren’t technically derivations, so they never got
substituted. To work around this, we can try to substitute this store
path during evaluation. This can happen any time a hash is provided.
@edolstra
Copy link
Member

Please check the flakes branch, it already does this:

td::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(std::move(actualPath), std::move(storePath)), *this};
        } catch (Error & e) {
            debug("substitution of input '%s' failed: %s", to_string(), e.what());
        }
    }

@matthewbauer
Copy link
Member Author

Actually this just applies to fetchTree right? I think it would still be useful for builtins.fetchurl & builtins.fetchTarball. I can make it match what fetchTree does though.

@Ericson2314
Copy link
Member

I get the other builtins.fetch* in https://github.com/NixOS/nix/pull/3754/files, but this might be still useful as an intermediate step.

@matthewbauer
Copy link
Member Author

Since fetchTree can do substitution on tarballs, I think we are mostly covered just doing fetchTree everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants