fetchhg: use lib.extendMkDerivation and support <pkg>.overrideAttrs (#423539)
				
					
				
			This commit is contained in:
		
						commit
						07f4a23c3c
					
				| @ -193,6 +193,9 @@ cffc27daf06c77c0d76bc35d24b929cb9d68c3c9 | ||||
| # nixos/kanidm: inherit lib, nixfmt | ||||
| 8f18393d380079904d072007fb19dc64baef0a3a | ||||
| 
 | ||||
| # fetchhg: format after refactoring with lib.extendMkDerivation and make overridable (#423539) | ||||
| 34a5b1eb23129f8fb62c677e3760903f6d43228f | ||||
| 
 | ||||
| # fetchurl: nixfmt-rfc-style | ||||
| ce21e97a1f20dee15da85c084f9d1148d84f853b | ||||
| 
 | ||||
|  | ||||
| @ -840,7 +840,7 @@ Used with CVS. Expects `cvsRoot`, `tag`, and `hash`. | ||||
| 
 | ||||
| ## `fetchhg` {#fetchhg} | ||||
| 
 | ||||
| Used with Mercurial. Expects `url`, `rev`, and `hash`. | ||||
| Used with Mercurial. Expects `url`, `rev`, `hash`, overridable with [`<pkg>.overrideAttrs`](#sec-pkg-overrideAttrs). | ||||
| 
 | ||||
| A number of fetcher functions wrap part of `fetchurl` and `fetchzip`. They are mainly convenience functions intended for commonly used destinations of source code in Nixpkgs. These wrapper fetchers are listed below. | ||||
| 
 | ||||
|  | ||||
| @ -3,39 +3,48 @@ | ||||
|   stdenvNoCC, | ||||
|   mercurial, | ||||
| }: | ||||
| { | ||||
|   name ? null, | ||||
|   url, | ||||
|   rev ? null, | ||||
|   sha256 ? null, | ||||
|   hash ? null, | ||||
|   fetchSubrepos ? false, | ||||
|   preferLocalBuild ? true, | ||||
| }: | ||||
| 
 | ||||
| if hash != null && sha256 != null then | ||||
|   throw "Only one of sha256 or hash can be set" | ||||
| else | ||||
|   # TODO: statically check if mercurial as the https support if the url starts with https. | ||||
|   stdenvNoCC.mkDerivation { | ||||
|     name = "hg-archive" + (lib.optionalString (name != null) "-${name}"); | ||||
|     builder = ./builder.sh; | ||||
|     nativeBuildInputs = [ mercurial ]; | ||||
| lib.extendMkDerivation { | ||||
|   constructDrv = stdenvNoCC.mkDerivation; | ||||
| 
 | ||||
|     impureEnvVars = lib.fetchers.proxyImpureEnvVars; | ||||
|   extendDrvArgs = | ||||
|     finalAttrs: | ||||
|     { | ||||
|       name ? null, | ||||
|       url, | ||||
|       rev ? null, | ||||
|       sha256 ? null, | ||||
|       hash ? null, | ||||
|       fetchSubrepos ? false, | ||||
|       preferLocalBuild ? true, | ||||
|     }: | ||||
|     # TODO: statically check if mercurial as the https support if the url starts with https. | ||||
|     { | ||||
|       name = "hg-archive" + (lib.optionalString (name != null) "-${name}"); | ||||
|       builder = ./builder.sh; | ||||
|       nativeBuildInputs = [ mercurial ]; | ||||
| 
 | ||||
|     subrepoClause = lib.optionalString fetchSubrepos "S"; | ||||
|       impureEnvVars = lib.fetchers.proxyImpureEnvVars; | ||||
| 
 | ||||
|     outputHashAlgo = if hash != null then null else "sha256"; | ||||
|     outputHashMode = "recursive"; | ||||
|     outputHash = | ||||
|       if hash != null then | ||||
|         hash | ||||
|       else if sha256 != null then | ||||
|         sha256 | ||||
|       else | ||||
|         lib.fakeSha256; | ||||
|       subrepoClause = lib.optionalString fetchSubrepos "S"; | ||||
| 
 | ||||
|     inherit url rev; | ||||
|     inherit preferLocalBuild; | ||||
|   } | ||||
|       outputHashAlgo = if finalAttrs.hash != null && finalAttrs.hash != "" then null else "sha256"; | ||||
|       outputHashMode = "recursive"; | ||||
|       outputHash = | ||||
|         lib.throwIf (finalAttrs.hash != null && sha256 != null) "Only one of sha256 or hash can be set" | ||||
|           ( | ||||
|             if finalAttrs.hash != null then | ||||
|               finalAttrs.hash | ||||
|             else if sha256 != null then | ||||
|               sha256 | ||||
|             else | ||||
|               "" | ||||
|           ); | ||||
| 
 | ||||
|       inherit url rev hash; | ||||
|       inherit preferLocalBuild; | ||||
|     }; | ||||
| 
 | ||||
|   # No ellipsis | ||||
|   inheritFunctionArgs = false; | ||||
| } | ||||
|  | ||||
| @ -5,7 +5,7 @@ | ||||
| }: | ||||
| 
 | ||||
| let | ||||
|   tests = tests-stdenv // test-extendMkDerivation // tests-go // tests-python; | ||||
|   tests = tests-stdenv // test-extendMkDerivation // tests-fetchhg // tests-go // tests-python; | ||||
| 
 | ||||
|   tests-stdenv = | ||||
|     let | ||||
| @ -131,6 +131,51 @@ let | ||||
|       }; | ||||
|     }; | ||||
| 
 | ||||
|   tests-fetchhg = | ||||
|     let | ||||
|       ruamel_0_18_14-hash = "sha256-HDkPPp1xI3uoGYlS9mwPp1ZjG2gKvx6vog0Blj6tBuI="; | ||||
|       ruamel_0_18_14-src = pkgs.fetchhg { | ||||
|         url = "http://hg.code.sf.net/p/ruamel-yaml/code"; | ||||
|         rev = "0.18.14"; | ||||
|         hash = ruamel_0_18_14-hash; | ||||
|       }; | ||||
|       ruamel_0_17_21-hash = "sha256-6PV0NyPQfd+4RBqoj5vJaOHShx+TJVHD2IamRinU0VU="; | ||||
|       ruamel_0_17_21-src = pkgs.fetchhg { | ||||
|         url = "http://hg.code.sf.net/p/ruamel-yaml/code"; | ||||
|         rev = "0.17.21"; | ||||
|         hash = ruamel_0_17_21-hash; | ||||
|       }; | ||||
|       ruamel_0_17_21-src-by-overriding = ruamel_0_18_14-src.overrideAttrs { | ||||
|         rev = "0.17.21"; | ||||
|         hash = ruamel_0_17_21-hash; | ||||
|       }; | ||||
|     in | ||||
|     { | ||||
|       hash-outputHash-equivalence = { | ||||
|         expr = ruamel_0_17_21-src.outputHash == ruamel_0_17_21-hash; | ||||
|         expected = true; | ||||
|       }; | ||||
| 
 | ||||
|       hash-overridability-outputHash = { | ||||
|         expr = ruamel_0_17_21-src-by-overriding.outputHash == ruamel_0_17_21-hash; | ||||
|         expected = true; | ||||
|       }; | ||||
| 
 | ||||
|       hash-overridability-drvPath = { | ||||
|         expr = | ||||
|           lib.isString ruamel_0_17_21-src-by-overriding.drvPath | ||||
|           && ruamel_0_17_21-src-by-overriding.drvPath == ruamel_0_17_21-src.drvPath; | ||||
|         expected = true; | ||||
|       }; | ||||
| 
 | ||||
|       hash-overridability-outPath = { | ||||
|         expr = | ||||
|           lib.isString ruamel_0_17_21-src-by-overriding.outPath | ||||
|           && ruamel_0_17_21-src-by-overriding.outPath == ruamel_0_17_21-src.outPath; | ||||
|         expected = true; | ||||
|       }; | ||||
|     }; | ||||
| 
 | ||||
|   tests-go = | ||||
|     let | ||||
|       pet_0_3_4 = pkgs.buildGoModule rec { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Yueh-Shun Li
						Yueh-Shun Li