aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/builtins/fetchurl.cc
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2020-08-06 18:13:14 -0500
committerMatthew Bauer <mjbauer95@gmail.com>2020-08-06 18:19:09 -0500
commit641c95070162595c71a1f775a2364cd8533e1c4b (patch)
tree8841b76f65b53fe824c052abeb709978bd3b77cb /src/libstore/builtins/fetchurl.cc
parent24e07c428f21f28df2a41a7a9851d5867f34753a (diff)
Add hashed-mirrors back
Some users have their own hashed-mirrors setup, that is used to mirror things in addition to what’s available on tarballs.nixos.org. Although this should be feasable to do with a Binary Cache, it’s not always easy, since you have to remember what "name" each of the tarballs has. Continuing to support hashed-mirrors is cheap, so it’s best to leave support in Nix. Note that NIX_HASHED_MIRRORS is also supported in Nixpkgs through fetchurl.nix. Note that this excludes tarballs.nixos.org from the default, as in \#3689. All of these are available on cache.nixos.org.
Diffstat (limited to 'src/libstore/builtins/fetchurl.cc')
-rw-r--r--src/libstore/builtins/fetchurl.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc
index 6585a480d..2048f8f87 100644
--- a/src/libstore/builtins/fetchurl.cc
+++ b/src/libstore/builtins/fetchurl.cc
@@ -58,6 +58,20 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
}
};
+ /* Try the hashed mirrors first. */
+ if (getAttr("outputHashMode") == "flat")
+ for (auto hashedMirror : settings.hashedMirrors.get())
+ try {
+ if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/';
+ auto ht = parseHashType(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());
+ }
+
+ /* Otherwise try the specified URL. */
fetch(mainUrl);
}