summary refs log tree commit diff
path: root/pkgs/build-support/fetchsourcehut/default.nix
blob: 2b1feaa496e45ff990f34c4a94634a4e72f80403 (plain) (blame)
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
{ fetchgit, fetchhg, fetchzip, lib }:

{ owner
, repo, rev
, domain ? "sr.ht"
, vc ? "git"
, name ? "source"
, fetchSubmodules ? false
, ... # For hash agility
} @ args:

with lib;

assert (lib.assertOneOf "vc" vc [ "hg" "git" ]);

let
  baseUrl = "https://${vc}.${domain}/${owner}/${repo}";
  baseArgs = {
    inherit name;
  } // removeAttrs args [
    "owner" "repo" "rev" "domain" "vc" "name" "fetchSubmodules"
  ];
  vcArgs = baseArgs // {
    inherit rev;
    url = baseUrl;
  };
  fetcher = if fetchSubmodules then vc else "zip";
  cases = {
    git = {
      fetch = fetchgit;
      arguments = vcArgs // { fetchSubmodules = true; };
    };
    hg = {
      fetch = fetchhg;
      arguments = vcArgs // { fetchSubrepos = true; };
    };
    zip = {
      fetch = fetchzip;
      arguments = baseArgs // {
        url = "${baseUrl}/archive/${rev}.tar.gz";
        extraPostFetch = optionalString (vc == "hg") ''
          rm -f "$out/.hg_archival.txt"
        ''; # impure file; see #12002
      };
    };
  };
in cases.${fetcher}.fetch cases.${fetcher}.arguments // {
  inherit rev;
  meta.homepage = "${baseUrl}";
}