forked from rarias/jungle
Add fetchGitMirror function
This commit is contained in:
@@ -14,16 +14,19 @@
|
||||
, openblas
|
||||
, ovni
|
||||
, gitBranch ? "master"
|
||||
, gitURL ? "ssh://git@bscpm04.bsc.es/rarias/bench6.git"
|
||||
, gitCommit ? "bf29a53113737c3aa74d2fe3d55f59868faea7b4"
|
||||
, gitUrls ? [
|
||||
"ssh://git@bscpm04.bsc.es/rarias/bench6.git"
|
||||
"https://github.com/rodarima/bench6.git"
|
||||
]
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "bench6";
|
||||
version = "${src.shortRev}";
|
||||
|
||||
src = builtins.fetchGit {
|
||||
url = gitURL;
|
||||
src = lib.fetchGitMirror {
|
||||
urls = gitUrls;
|
||||
ref = gitBranch;
|
||||
rev = gitCommit;
|
||||
};
|
||||
|
||||
30
pkgs/lib.nix
Normal file
30
pkgs/lib.nix
Normal file
@@ -0,0 +1,30 @@
|
||||
{ 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;
|
||||
};
|
||||
})
|
||||
Reference in New Issue
Block a user