8be7956fc0
There are a few instances of `fetchFromGitLab` in the repo, for instance `gtk-doc.src`. My primary goal when writing this was changing the output derivation following #11. This is doable with a lot less diff in `fetchFromGitLab`, but it's worth asking whether both fetchers should be different and why. I think a lot of the divergence comes from years of random commits rather than from design. Reviewed-by: @isabelroses Co-authored-by: Julie B. <no-reply@bbjubjub.fr> Reviewed-on: #14 Co-authored-by: Ghost <> Co-committed-by: Ghost <>
39 lines
1.5 KiB
Nix
39 lines
1.5 KiB
Nix
{ lib, fetchgit, fetchzip }:
|
|
|
|
lib.makeOverridable (
|
|
# gitlab example
|
|
{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", group ? null
|
|
, pname ? lib.concatStringsSep "-" ([ "source" domain ] ++ (lib.optional (group != null) group) ++ [ owner repo ])
|
|
, name ? "${pname}-${rev}"
|
|
, fetchSubmodules ? false, leaveDotGit ? false
|
|
, deepClone ? false, forceFetchGit ? false
|
|
, sparseCheckout ? []
|
|
, ... # For hash agility
|
|
} @ 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;
|
|
passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" "fetchSubmodules" "forceFetchGit" "leaveDotGit" "deepClone" ];
|
|
|
|
useFetchGit = fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != []);
|
|
fetcher = if useFetchGit then fetchgit else fetchzip;
|
|
|
|
gitRepoUrl = "${protocol}://${domain}/${slug}.git";
|
|
|
|
fetcherArgs = (if useFetchGit then {
|
|
inherit rev deepClone fetchSubmodules sparseCheckout leaveDotGit;
|
|
url = gitRepoUrl;
|
|
} else {
|
|
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}";
|
|
|
|
passthru = {
|
|
inherit gitRepoUrl;
|
|
};
|
|
}) // passthruAttrs // { inherit name; };
|
|
in
|
|
|
|
fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev owner repo; }
|
|
)
|