summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/fetchgitiles/default.nix
blob: 66f162cfa3e51ad36ae15f622a682711ae5a94ee (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
{
  fetchzip,
  repoRevToNameMaybe,
  lib,
}:

lib.makeOverridable (
  {
    url,
    rev ? null,
    tag ? null,
    name ? repoRevToNameMaybe url (lib.revOrTag rev tag) "gitiles",
    ...
  }@args:

  assert (
    lib.xor (tag == null) (rev == null)
    || throw "fetchFromGitiles requires one of either `rev` or `tag` to be provided (not both)."
  );

  let
    realrev = (if tag != null then "refs/tags/" + tag else rev);
  in

  fetchzip (
    {
      inherit name;
      url = "${url}/+archive/${realrev}.tar.gz";
      stripRoot = false;
      meta.homepage = url;
    }
    // removeAttrs args [
      "url"
      "tag"
      "rev"
    ]
  )
  // {
    inherit rev tag;
  }
)