Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-24.11] fetch{gitlab,gitiles}: add tag argument #367994

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions pkgs/build-support/fetchgitiles/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,36 @@
lib.makeOverridable (
{
url,
rev,
rev ? null,
tag ? null,
name ? "source",
...
}@args:

assert (
lib.assertMsg (lib.xor (tag == null) (
rev == null
)) "fetchFromGitiles requires one of either `rev` or `tag` to be provided (not both)."
);

let
realrev = (if tag != null then "refs/tags/" + tag else rev);
in

fetchzip (
{
inherit name;
url = "${url}/+archive/${rev}.tar.gz";
url = "${url}/+archive/${realrev}.tar.gz";
stripRoot = false;
meta.homepage = url;
}
// removeAttrs args [
"url"
"tag"
"rev"
]
)
// {
inherit rev;
inherit rev tag;
}
)
133 changes: 100 additions & 33 deletions pkgs/build-support/fetchgitlab/default.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,103 @@
{ lib, fetchgit, fetchzip }:
{
lib,
fetchgit,
fetchzip,
}:

lib.makeOverridable (
# gitlab example
{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null
, 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; }
# gitlab example
{
owner,
repo,
rev ? null,
tag ? null,
protocol ? "https",
domain ? "gitlab.com",
name ? "source",
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
]
);
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug;
escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] (
if tag != null then "refs/tags/" + tag else rev
);
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=${escapedRev}";

passthru = {
inherit gitRepoUrl;
};
}
)
// passthruAttrs
// {
inherit name;
};
in

fetcher fetcherArgs
// {
meta.homepage = "${protocol}://${domain}/${slug}/";
inherit
tag
rev
owner
repo
;
}
)
Loading