Add fetchGitMirror function
All checks were successful
CI / build:cross (pull_request) Successful in 6s
CI / build:all (pull_request) Successful in 19s

This commit is contained in:
Rodrigo Arias 2025-10-16 10:29:08 +02:00
parent 3edf00af0c
commit 76aa169fe8
3 changed files with 47 additions and 14 deletions

View File

@ -1,9 +1,10 @@
final: /* Future last stage */
prev: /* Previous stage */
with final.lib;
#with final.lib;
let
lib = prev.lib;
callPackage = final.callPackage;
bscPkgs = {
@ -96,15 +97,18 @@ let
};
};
# Load our custom lib functions with import, callPackage fails.
lib' = import ./pkgs/lib.nix { lib = prev.lib; };
# For now, only build toplevel packages in CI/Hydra
pkgsTopLevel = filterAttrs (_: isDerivation) bscPkgs;
pkgsTopLevel = lib.filterAttrs (_: lib.isDerivation) bscPkgs;
# Native build in that platform doesn't imply cross build works
canCrossCompile = platform: pkg:
(isDerivation pkg) &&
(lib.isDerivation pkg) &&
# Must be defined explicitly
(pkg.meta.cross or false) &&
(meta.availableOn platform pkg);
(lib.meta.availableOn platform pkg);
# For now only RISC-V
crossSet = { riscv64 = final.pkgsCross.riscv64.bsc.pkgsTopLevel; };
@ -122,21 +126,17 @@ let
'';
pkgsList = buildList "ci-pkgs" (builtins.attrValues pkgsTopLevel);
testsList = buildList "ci-tests" (collect isDerivation tests);
testsList = buildList "ci-tests" (lib.collect lib.isDerivation tests);
allList = buildList' "ci-all" [ pkgsList testsList ];
# For now only RISC-V
crossList = buildList "ci-cross"
(filter
(lib.filter
(canCrossCompile final.pkgsCross.riscv64.stdenv.hostPlatform)
(builtins.attrValues crossSet.riscv64));
in bscPkgs // {
lib = prev.lib // {
maintainers = prev.lib.maintainers // {
bsc = import ./pkgs/maintainers.nix;
};
};
lib = lib';
# Prevent accidental usage of bsc-ci attribute
bsc-ci = throw "the bsc-ci attribute is deprecated, use bsc.ci";

View File

@ -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
View 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;
};
})