From 0ba1f47823afb316cbea0fed7bd74c9d0a8bb50a Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 9 Jul 2025 01:08:38 +0800 Subject: [PATCH] fetchhg: make argument hash overridable (cherry picked from commit ef2f8315bf538f1e76ca2f2257a53f583df3989e) --- doc/build-helpers/fetchers.chapter.md | 2 +- pkgs/build-support/fetchhg/default.nix | 10 +++--- pkgs/test/overriding.nix | 47 +++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/doc/build-helpers/fetchers.chapter.md b/doc/build-helpers/fetchers.chapter.md index 997f97f81bdb..ee35b2339b0c 100644 --- a/doc/build-helpers/fetchers.chapter.md +++ b/doc/build-helpers/fetchers.chapter.md @@ -836,7 +836,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 [`.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. diff --git a/pkgs/build-support/fetchhg/default.nix b/pkgs/build-support/fetchhg/default.nix index 4c8a8f312929..f22e32aca44a 100644 --- a/pkgs/build-support/fetchhg/default.nix +++ b/pkgs/build-support/fetchhg/default.nix @@ -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; }; diff --git a/pkgs/test/overriding.nix b/pkgs/test/overriding.nix index 27f57ab1ab9d..29bdbf2fd8fd 100644 --- a/pkgs/test/overriding.nix +++ b/pkgs/test/overriding.nix @@ -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 {