Unverified Commit 07f4a23c authored by Yueh-Shun Li's avatar Yueh-Shun Li Committed by GitHub
Browse files

fetchhg: use `lib.extendMkDerivation` and support `<pkg>.overrideAttrs` (#423539)

parents 481cdeee 3d7b2882
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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

+1 −1
Original line number Diff line number Diff line
@@ -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.

+40 −31
Original line number Diff line number Diff line
@@ -3,6 +3,12 @@
  stdenvNoCC,
  mercurial,
}:

lib.extendMkDerivation {
  constructDrv = stdenvNoCC.mkDerivation;

  extendDrvArgs =
    finalAttrs:
    {
      name ? null,
      url,
@@ -12,12 +18,8 @@
      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 ];
@@ -26,16 +28,23 @@ else

      subrepoClause = lib.optionalString fetchSubrepos "S";

    outputHashAlgo = if hash != null then null else "sha256";
      outputHashAlgo = if finalAttrs.hash != null && finalAttrs.hash != "" then null else "sha256";
      outputHashMode = "recursive";
      outputHash =
      if hash != null then
        hash
        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
        lib.fakeSha256;
              ""
          );

    inherit url rev;
      inherit url rev hash;
      inherit preferLocalBuild;
    };

  # No ellipsis
  inheritFunctionArgs = false;
}
+46 −1
Original line number Diff line number Diff line
@@ -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 {