summaryrefslogtreecommitdiff
path: root/pkgs/build-support/fetchradiclepatch/default.nix
blob: 22f9ea6c481792a03ca6c5fe458c75879c89248d (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
{
  fetchFromRadicle,
  jq,
  lib,
}:

lib.makeOverridable (
  {
    revision,
    postFetch ? "",
    nativeBuildInputs ? [ ],
    ...
  }@args:

  assert lib.assertMsg (
    !args ? rev && !args ? tag
  ) "fetchRadiclePatch does not accept `rev` or `tag` arguments.";

  fetchFromRadicle (
    {
      nativeBuildInputs = [ jq ] ++ nativeBuildInputs;
      rev = revision;
      leaveDotGit = true;
      postFetch = ''
        { read -r head; read -r base; } < <(jq -r '.oid, .base' $out/0)
        git -C $out fetch --depth=1 "$url" "$base" "$head"
        git -C $out diff "$base" "$head" > patch
        rm -r $out
        mv patch $out
        ${postFetch}
      '';
    }
    // removeAttrs args [
      "revision"
      "postFetch"
      "nativeBuildInputs"
      "leaveDotGit"
    ]
  )
  // {
    inherit revision;
  }
)