summary refs log tree commit diff
path: root/pkgs/build-support/fetchgitlab/default.nix
blob: 77512510a7c6473bfbc8783eec7f0345c5d7c050 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{ fetchzip, lib }:

# gitlab example
{ owner, repo, rev, domain ? "gitlab.com", name ? "source", group ? null
, ... # For hash agility
} @ args:

with lib;

let
  slug = concatStringsSep "/"
    ((optional (group != null) group) ++ [ owner repo ]);

  escapedSlug = replaceStrings ["." "/"] ["%2E" "%2F"] slug;
  escapedRev = replaceStrings ["+" "%" "/"] ["%2B" "%25" "%2F"] rev;
in

fetchzip ({
  inherit name;
  url = "https://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
  meta.homepage = "https://${domain}/${slug}/";
} // removeAttrs args [ "domain" "owner" "group" "repo" "rev" ]) // { inherit rev; }