fetchhg: make argument hash overridable

This commit is contained in:
Yueh-Shun Li 2025-07-09 01:08:38 +08:00
parent 5e7cb7d976
commit ef2f8315bf
3 changed files with 52 additions and 7 deletions

View File

@ -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.

View File

@ -28,22 +28,22 @@ lib.extendMkDerivation {
subrepoClause = lib.optionalString fetchSubrepos "S";
outputHashAlgo = if hash != null && hash != "" then null else "sha256";
outputHashAlgo = if finalAttrs.hash != null && finalAttrs.hash != "" then null else "sha256";
outputHashMode = "recursive";
outputHash =
lib.throwIf
(hash != null && sha256 != null)
(finalAttrs.hash != null && sha256 != null)
"Only one of sha256 or hash can be set"
(
if hash != null then
hash
if finalAttrs.hash != null then
finalAttrs.hash
else if sha256 != null then
sha256
else
""
);
inherit url rev;
inherit url rev hash;
inherit preferLocalBuild;
};

View File

@ -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 {