diff options
author | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-07-28 15:36:45 -0400 |
---|---|---|
committer | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-07-28 15:36:45 -0400 |
commit | cfe96bd7ce06c3153b036447f9a933f2231a2029 (patch) | |
tree | 991e0e5b2adda907a9305e622fa54f7a401969d5 /src/libstore/builtins/fetchurl.cc | |
parent | d9fb9e9f26e29d9d9001af700deada32ca740cf6 (diff) | |
parent | b8eea7e81af53905be7845dffc6d0a83ea8edc97 (diff) |
Merge branch 'master' of github.com:NixOS/nix into ca-drv
Diffstat (limited to 'src/libstore/builtins/fetchurl.cc')
-rw-r--r-- | src/libstore/builtins/fetchurl.cc | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc index 1cfe4a46a..03bb77488 100644 --- a/src/libstore/builtins/fetchurl.cc +++ b/src/libstore/builtins/fetchurl.cc @@ -58,18 +58,24 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData) } }; + /* We always have one output, and if it's a fixed-output derivation (as + checked below) it must be the only output */ + auto & output = drv.outputs.begin()->second; + /* Try the hashed mirrors first. */ - if (getAttr("outputHashMode") == "flat") - for (auto hashedMirror : settings.hashedMirrors.get()) - try { - if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; - auto ht = parseHashTypeOpt(getAttr("outputHashAlgo")); - auto h = Hash(getAttr("outputHash"), ht); - fetch(hashedMirror + printHashType(*h.type) + "/" + h.to_string(Base16, false)); - return; - } catch (Error & e) { - debug(e.what()); + if (auto hash = std::get_if<DerivationOutputFixed>(&output.output)) { + if (hash->hash.method == FileIngestionMethod::Flat) { + for (auto hashedMirror : settings.hashedMirrors.get()) { + try { + if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/'; + fetch(hashedMirror + printHashType(hash->hash.hash.type) + "/" + hash->hash.hash.to_string(Base16, false)); + return; + } catch (Error & e) { + debug(e.what()); + } } + } + } /* Otherwise try the specified URL. */ fetch(mainUrl); |