summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/fetchhg/default.nix
blob: acf1621bb1db461db00f0a547e556d768e649fe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
  lib,
  stdenvNoCC,
  mercurial,
}:

lib.extendMkDerivation {
  constructDrv = stdenvNoCC.mkDerivation;

  extendDrvArgs =
    finalAttrs:
    {
      name ? null,
      url,
      rev ? null,
      sha256 ? null,
      hash ? null,
      fetchSubrepos ? false,
      preferLocalBuild ? true,
    }:
    # TODO: statically check if mercurial has https support if the url starts with https.
    {
      name = "hg-archive" + (lib.optionalString (name != null) "-${name}");
      builder = ./builder.sh;
      nativeBuildInputs = [ mercurial ];

      strictDeps = true;
      __structuredAttrs = true;

      impureEnvVars = lib.fetchers.proxyImpureEnvVars;

      subrepoClause = lib.optionalString fetchSubrepos "S";

      outputHashAlgo = if finalAttrs.hash != null && finalAttrs.hash != "" then null else "sha256";
      outputHashMode = "recursive";
      outputHash =
        if (hash != null && sha256 != null) then
          throw "Only one of sha256 or hash can be set"
        else
          (
            if finalAttrs.hash != null then
              finalAttrs.hash
            else if sha256 != null then
              sha256
            else
              ""
          );

      inherit url rev hash;
      inherit preferLocalBuild;
    };

  # No ellipsis
  inheritFunctionArgs = false;
}