Files
nixpkgs/pkgs/build-support/fetchgitlab/default.nix
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

104 lines
2.2 KiB
Nix

{
lib,
repoRevToNameMaybe,
fetchgit,
fetchzip,
}:
lib.makeOverridable (
# gitlab example
{
owner,
repo,
rev ? null,
tag ? null,
name ? repoRevToNameMaybe repo (lib.revOrTag rev tag) "gitlab",
protocol ? "https",
domain ? "gitlab.com",
group ? null,
fetchSubmodules ? false,
leaveDotGit ? false,
deepClone ? false,
forceFetchGit ? false,
sparseCheckout ? [ ],
... # For hash agility
}@args:
assert (
lib.assertMsg (lib.xor (tag == null) (
rev == null
)) "fetchFromGitLab requires one of either `rev` or `tag` to be provided (not both)."
);
let
slug = lib.concatStringsSep "/" (
(lib.optional (group != null) group)
++ [
owner
repo
]
);
revWithTag = if tag != null then "refs/tags/" + tag else rev;
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
escapedRevWithTag = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] revWithTag;
passthruAttrs = removeAttrs args [
"protocol"
"domain"
"owner"
"group"
"repo"
"rev"
"tag"
"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
tag
fetchSubmodules
sparseCheckout
leaveDotGit
;
url = gitRepoUrl;
}
else
{
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRevWithTag}";
passthru = {
inherit gitRepoUrl;
};
}
)
// passthruAttrs
// {
inherit name;
};
in
fetcher fetcherArgs
// {
meta.homepage = "${protocol}://${domain}/${slug}/";
inherit
tag
owner
repo
;
rev = revWithTag;
}
)