nixpkgs-suyu/pkgs/build-support/fetchgitlab/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
1.1 KiB
Nix
Raw Normal View History

{ fetchgit, fetchzip, lib }:
# gitlab example
{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null
, fetchSubmodules ? false, leaveDotGit ? false, deepClone ? false
, ... # For hash agility
2019-11-24 20:54:46 +01:00
} @ args:
let
slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]);
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev;
2021-11-18 19:53:46 +01:00
passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" ];
useFetchGit = deepClone || fetchSubmodules || leaveDotGit;
fetcher = if useFetchGit then fetchgit else fetchzip;
2019-11-24 20:54:46 +01:00
fetcherArgs = (if useFetchGit then {
inherit rev deepClone fetchSubmodules leaveDotGit;
url = "${protocol}://${domain}/${slug}.git";
} else {
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
}) // passthruAttrs // { inherit name; };
2019-11-24 20:54:46 +01:00
in
fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev; }