mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-16 06:47:09 +03:00
7aae279ad9
a67950f20b
added `url` attribute
from `fetchurl` and therefore also from `fetchzip`.
We previously relied on `url` from fetchgit-based fetchers
to find the repo URL but now it will just return tarballs
in the case of `fetchFrom{GitHub,GitLab}`.
Let’s add an attribute to `fetch{git,FromGitHub,FromGitLab}`
to expose a repo URL consistently.
33 lines
1.1 KiB
Nix
33 lines
1.1 KiB
Nix
{ 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
|
|
} @ 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" ];
|
|
|
|
useFetchGit = deepClone || fetchSubmodules || leaveDotGit;
|
|
fetcher = if useFetchGit then fetchgit else fetchzip;
|
|
|
|
gitRepoUrl = "${protocol}://${domain}/${slug}.git";
|
|
|
|
fetcherArgs = (if useFetchGit then {
|
|
inherit rev deepClone fetchSubmodules 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; }
|