fetchurl: provide fetchurl.resolveUrl

This commit is contained in:
Yueh-Shun Li
2025-12-18 08:03:43 +08:00
parent 7c4673bbb8
commit ca050c53b2
+16 -10
View File
@@ -35,6 +35,18 @@ let
# "gnu", etc.).
sites = builtins.attrNames mirrors;
resolveUrl =
url:
let
mirrorSplit = lib.match "mirror://([[:alpha:]]+)/(.+)" url;
mirrorName = lib.head mirrorSplit;
mirrorList = mirrors."${mirrorName}" or (throw "unknown mirror:// site ${mirrorName}");
in
if mirrorSplit == null || mirrorName == null then
[ url ]
else
map (mirror: mirror + lib.elemAt mirrorSplit 1) mirrorList;
impureEnvVars =
lib.fetchers.proxyImpureEnvVars
++ [
@@ -223,16 +235,7 @@ lib.extendMkDerivation {
finalHashHasColon = lib.hasInfix ":" finalAttrs.hash;
finalHashColonMatch = lib.match "([^:]+)[:](.*)" finalAttrs.hash;
resolvedUrl =
let
mirrorSplit = lib.match "mirror://([[:alpha:]]+)/(.+)" url;
mirrorName = lib.head mirrorSplit;
mirrorList = mirrors."${mirrorName}" or (throw "unknown mirror:// site ${mirrorName}");
in
if mirrorSplit == null || mirrorName == null then
url
else
"${lib.head mirrorList}${lib.elemAt mirrorSplit 1}";
resolvedUrl = lib.head (resolveUrl url);
in
derivationArgs
@@ -339,3 +342,6 @@ lib.extendMkDerivation {
# No ellipsis
inheritFunctionArgs = false;
}
// {
inherit resolveUrl;
}