Add fetchGitMirror function
This commit is contained in:
		
							parent
							
								
									59d7374f78
								
							
						
					
					
						commit
						cc63e6f3f3
					
				
							
								
								
									
										22
									
								
								overlay.nix
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								overlay.nix
									
									
									
									
									
								
							| @ -1,9 +1,8 @@ | |||||||
| final: /* Future last stage */ | final: /* Future last stage */ | ||||||
| prev:  /* Previous stage */ | prev:  /* Previous stage */ | ||||||
| 
 | 
 | ||||||
| with final.lib; |  | ||||||
| 
 |  | ||||||
| let | let | ||||||
|  |   lib = prev.lib; | ||||||
|   callPackage = final.callPackage; |   callPackage = final.callPackage; | ||||||
| 
 | 
 | ||||||
|   bscPkgs = { |   bscPkgs = { | ||||||
| @ -97,15 +96,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 |   # 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 |   # Native build in that platform doesn't imply cross build works | ||||||
|   canCrossCompile = platform: pkg: |   canCrossCompile = platform: pkg: | ||||||
|     (isDerivation pkg) && |     (lib.isDerivation pkg) && | ||||||
|     # Must be defined explicitly |     # Must be defined explicitly | ||||||
|     (pkg.meta.cross or false) && |     (pkg.meta.cross or false) && | ||||||
|     (meta.availableOn platform pkg); |     (lib.meta.availableOn platform pkg); | ||||||
| 
 | 
 | ||||||
|   # For now only RISC-V |   # For now only RISC-V | ||||||
|   crossSet = { riscv64 = final.pkgsCross.riscv64.bsc.pkgsTopLevel; }; |   crossSet = { riscv64 = final.pkgsCross.riscv64.bsc.pkgsTopLevel; }; | ||||||
| @ -123,21 +125,17 @@ let | |||||||
|     ''; |     ''; | ||||||
| 
 | 
 | ||||||
|   pkgsList = buildList "ci-pkgs" (builtins.attrValues pkgsTopLevel); |   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 ]; |   allList = buildList' "ci-all" [ pkgsList testsList ]; | ||||||
|   # For now only RISC-V |   # For now only RISC-V | ||||||
|   crossList = buildList "ci-cross" |   crossList = buildList "ci-cross" | ||||||
|     (filter |     (lib.filter | ||||||
|       (canCrossCompile final.pkgsCross.riscv64.stdenv.hostPlatform) |       (canCrossCompile final.pkgsCross.riscv64.stdenv.hostPlatform) | ||||||
|         (builtins.attrValues crossSet.riscv64)); |         (builtins.attrValues crossSet.riscv64)); | ||||||
| 
 | 
 | ||||||
| in bscPkgs // { | in bscPkgs // { | ||||||
| 
 | 
 | ||||||
|   lib = prev.lib // { |   lib = lib'; | ||||||
|     maintainers = prev.lib.maintainers // { |  | ||||||
|       bsc = import ./pkgs/maintainers.nix; |  | ||||||
|     }; |  | ||||||
|   }; |  | ||||||
| 
 | 
 | ||||||
|   # Prevent accidental usage of bsc-ci attribute |   # Prevent accidental usage of bsc-ci attribute | ||||||
|   bsc-ci = throw "the bsc-ci attribute is deprecated, use bsc.ci"; |   bsc-ci = throw "the bsc-ci attribute is deprecated, use bsc.ci"; | ||||||
|  | |||||||
| @ -14,16 +14,19 @@ | |||||||
| , openblas | , openblas | ||||||
| , ovni | , ovni | ||||||
| , gitBranch ? "master" | , gitBranch ? "master" | ||||||
| , gitURL ? "ssh://git@bscpm04.bsc.es/rarias/bench6.git" |  | ||||||
| , gitCommit ? "bf29a53113737c3aa74d2fe3d55f59868faea7b4" | , gitCommit ? "bf29a53113737c3aa74d2fe3d55f59868faea7b4" | ||||||
|  | , gitUrls ? [ | ||||||
|  |   "ssh://git@bscpm04.bsc.es/rarias/bench6.git" | ||||||
|  |   "https://github.com/rodarima/bench6.git" | ||||||
|  | ] | ||||||
| }: | }: | ||||||
| 
 | 
 | ||||||
| stdenv.mkDerivation rec { | stdenv.mkDerivation rec { | ||||||
|   pname = "bench6"; |   pname = "bench6"; | ||||||
|   version = "${src.shortRev}"; |   version = "${src.shortRev}"; | ||||||
| 
 | 
 | ||||||
|   src = builtins.fetchGit { |   src = lib.fetchGitMirror { | ||||||
|     url = gitURL; |     urls = gitUrls; | ||||||
|     ref = gitBranch; |     ref = gitBranch; | ||||||
|     rev = gitCommit; |     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; | ||||||
|  |   }; | ||||||
|  | }) | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user