jungle/pkgs/lib.nix
Rodrigo Arias Mallo 76aa169fe8
All checks were successful
CI / build:cross (pull_request) Successful in 6s
CI / build:all (pull_request) Successful in 19s
Add fetchGitMirror function
2025-10-20 16:30:41 +02:00

31 lines
978 B
Nix

{ lib }:
let
# If not supported, fall back to tryEval, which will fail in the first case.
safeCatchAll = if (builtins ? catchAll)
then builtins.catchAll
else e: (builtins.tryEval e) // { msg = ""; };
in lib.extend (_: lib: {
# Same as fetchGit but accepts a list of mirror urls
fetchGitMirror = { urls, ... } @ args:
let
cleanArgs = lib.removeAttrs args [ "urls" ];
fetchUrl = url: builtins.fetchGit (cleanArgs // { inherit url; });
safeFetch = url: safeCatchAll (fetchUrl url);
complain = url:
let
r = safeFetch url;
in
if (r.success) then r
else lib.warn "cannot fetch ${url}, trying next
mirror:${builtins.replaceStrings ["\n" ] ["\n> "] ("\n"+r.msg)}" r;
fetchList = lib.map (url: complain url) urls;
bad = throw "cannot fetch from any mirror";
good = lib.findFirst (e: e.success) bad fetchList;
in good.value;
maintainers = lib.maintainers // {
bsc = import ./maintainers.nix;
};
})