mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
No global settings in libnixfetchers
and libnixflake
Progress on #5638
There are still a global fetcher and eval settings, but they are pushed
down into `libnixcmd`, which is a lot less bad a place for this sort of
thing.
Continuing process pioneered in
52bfccf8d8
.
This commit is contained in:
parent
b57c361097
commit
3fc77f281e
50 changed files with 401 additions and 271 deletions
|
@ -31,7 +31,9 @@ struct GitArchiveInputScheme : InputScheme
|
|||
{
|
||||
virtual std::optional<std::pair<std::string, std::string>> accessHeaderFromToken(const std::string & token) const = 0;
|
||||
|
||||
std::optional<Input> inputFromURL(const ParsedURL & url, bool requireTree) const override
|
||||
std::optional<Input> inputFromURL(
|
||||
const fetchers::Settings & settings,
|
||||
const ParsedURL & url, bool requireTree) const override
|
||||
{
|
||||
if (url.scheme != schemeName()) return {};
|
||||
|
||||
|
@ -90,7 +92,7 @@ struct GitArchiveInputScheme : InputScheme
|
|||
if (ref && rev)
|
||||
throw BadURL("URL '%s' contains both a commit hash and a branch/tag name %s %s", url.url, *ref, rev->gitRev());
|
||||
|
||||
Input input;
|
||||
Input input{settings};
|
||||
input.attrs.insert_or_assign("type", std::string { schemeName() });
|
||||
input.attrs.insert_or_assign("owner", path[0]);
|
||||
input.attrs.insert_or_assign("repo", path[1]);
|
||||
|
@ -119,12 +121,14 @@ struct GitArchiveInputScheme : InputScheme
|
|||
};
|
||||
}
|
||||
|
||||
std::optional<Input> inputFromAttrs(const Attrs & attrs) const override
|
||||
std::optional<Input> inputFromAttrs(
|
||||
const fetchers::Settings & settings,
|
||||
const Attrs & attrs) const override
|
||||
{
|
||||
getStrAttr(attrs, "owner");
|
||||
getStrAttr(attrs, "repo");
|
||||
|
||||
Input input;
|
||||
Input input{settings};
|
||||
input.attrs = attrs;
|
||||
return input;
|
||||
}
|
||||
|
@ -168,18 +172,20 @@ struct GitArchiveInputScheme : InputScheme
|
|||
return input;
|
||||
}
|
||||
|
||||
std::optional<std::string> getAccessToken(const std::string & host) const
|
||||
std::optional<std::string> getAccessToken(const fetchers::Settings & settings, const std::string & host) const
|
||||
{
|
||||
auto tokens = fetchSettings.accessTokens.get();
|
||||
auto tokens = settings.accessTokens.get();
|
||||
if (auto token = get(tokens, host))
|
||||
return *token;
|
||||
return {};
|
||||
}
|
||||
|
||||
Headers makeHeadersWithAuthTokens(const std::string & host) const
|
||||
Headers makeHeadersWithAuthTokens(
|
||||
const fetchers::Settings & settings,
|
||||
const std::string & host) const
|
||||
{
|
||||
Headers headers;
|
||||
auto accessToken = getAccessToken(host);
|
||||
auto accessToken = getAccessToken(settings, host);
|
||||
if (accessToken) {
|
||||
auto hdr = accessHeaderFromToken(*accessToken);
|
||||
if (hdr)
|
||||
|
@ -295,7 +301,7 @@ struct GitArchiveInputScheme : InputScheme
|
|||
locking. FIXME: in the future, we may want to require a Git
|
||||
tree hash instead of a NAR hash. */
|
||||
return input.getRev().has_value()
|
||||
&& (fetchSettings.trustTarballsFromGitForges ||
|
||||
&& (input.settings->trustTarballsFromGitForges ||
|
||||
input.getNarHash().has_value());
|
||||
}
|
||||
|
||||
|
@ -352,7 +358,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
|||
: "https://%s/api/v3/repos/%s/%s/commits/%s",
|
||||
host, getOwner(input), getRepo(input), *input.getRef());
|
||||
|
||||
Headers headers = makeHeadersWithAuthTokens(host);
|
||||
Headers headers = makeHeadersWithAuthTokens(*input.settings, host);
|
||||
|
||||
auto json = nlohmann::json::parse(
|
||||
readFile(
|
||||
|
@ -369,7 +375,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
|||
{
|
||||
auto host = getHost(input);
|
||||
|
||||
Headers headers = makeHeadersWithAuthTokens(host);
|
||||
Headers headers = makeHeadersWithAuthTokens(*input.settings, host);
|
||||
|
||||
// If we have no auth headers then we default to the public archive
|
||||
// urls so we do not run into rate limits.
|
||||
|
@ -389,7 +395,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
|||
void clone(const Input & input, const Path & destDir) const override
|
||||
{
|
||||
auto host = getHost(input);
|
||||
Input::fromURL(fmt("git+https://%s/%s/%s.git",
|
||||
Input::fromURL(*input.settings, fmt("git+https://%s/%s/%s.git",
|
||||
host, getOwner(input), getRepo(input)))
|
||||
.applyOverrides(input.getRef(), input.getRev())
|
||||
.clone(destDir);
|
||||
|
@ -426,7 +432,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
|||
auto url = fmt("https://%s/api/v4/projects/%s%%2F%s/repository/commits?ref_name=%s",
|
||||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"), *input.getRef());
|
||||
|
||||
Headers headers = makeHeadersWithAuthTokens(host);
|
||||
Headers headers = makeHeadersWithAuthTokens(*input.settings, host);
|
||||
|
||||
auto json = nlohmann::json::parse(
|
||||
readFile(
|
||||
|
@ -456,7 +462,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
|||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"),
|
||||
input.getRev()->to_string(HashFormat::Base16, false));
|
||||
|
||||
Headers headers = makeHeadersWithAuthTokens(host);
|
||||
Headers headers = makeHeadersWithAuthTokens(*input.settings, host);
|
||||
return DownloadUrl { url, headers };
|
||||
}
|
||||
|
||||
|
@ -464,7 +470,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
|||
{
|
||||
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
|
||||
// FIXME: get username somewhere
|
||||
Input::fromURL(fmt("git+https://%s/%s/%s.git",
|
||||
Input::fromURL(*input.settings, fmt("git+https://%s/%s/%s.git",
|
||||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
|
||||
.applyOverrides(input.getRef(), input.getRev())
|
||||
.clone(destDir);
|
||||
|
@ -496,7 +502,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
|||
auto base_url = fmt("https://%s/%s/%s",
|
||||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"));
|
||||
|
||||
Headers headers = makeHeadersWithAuthTokens(host);
|
||||
Headers headers = makeHeadersWithAuthTokens(*input.settings, host);
|
||||
|
||||
std::string refUri;
|
||||
if (ref == "HEAD") {
|
||||
|
@ -543,14 +549,14 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
|||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"),
|
||||
input.getRev()->to_string(HashFormat::Base16, false));
|
||||
|
||||
Headers headers = makeHeadersWithAuthTokens(host);
|
||||
Headers headers = makeHeadersWithAuthTokens(*input.settings, host);
|
||||
return DownloadUrl { url, headers };
|
||||
}
|
||||
|
||||
void clone(const Input & input, const Path & destDir) const override
|
||||
{
|
||||
auto host = maybeGetStrAttr(input.attrs, "host").value_or("git.sr.ht");
|
||||
Input::fromURL(fmt("git+https://%s/%s/%s",
|
||||
Input::fromURL(*input.settings, fmt("git+https://%s/%s/%s",
|
||||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
|
||||
.applyOverrides(input.getRef(), input.getRev())
|
||||
.clone(destDir);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue