Skip to content
Closed
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
13 changes: 10 additions & 3 deletions src/libfetchers/github.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <optional>
#include <nlohmann/json.hpp>
#include <fstream>
#include <boost/algorithm/string/replace.hpp>

namespace nix::fetchers {

Expand Down Expand Up @@ -332,9 +333,11 @@ struct GitLabInputScheme : GitArchiveInputScheme
Hash getRevFromRef(nix::ref<Store> store, const Input & input) const override
{
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
auto owner = boost::replace_all_copy(getStrAttr(input.attrs, "owner"), "/", "%2F");
auto repo = boost::replace_all_copy(getStrAttr(input.attrs, "repo"), "/", "%2F");
// See rate limiting note below
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());
host, owner, repo, *input.getRef());

Headers headers = makeHeadersWithAuthTokens(host);

Expand All @@ -355,8 +358,10 @@ struct GitLabInputScheme : GitArchiveInputScheme
// is 10 reqs/sec/ip-addr. See
// https://docs.gitlab.com/ee/user/gitlab_com/index.html#gitlabcom-specific-rate-limits
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
auto owner = boost::replace_all_copy(getStrAttr(input.attrs, "owner"), "/", "%2F");
auto repo = boost::replace_all_copy(getStrAttr(input.attrs, "repo"), "/", "%2F");
auto url = fmt("https://%s/api/v4/projects/%s%%2F%s/repository/archive.tar.gz?sha=%s",
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"),
host, owner, repo,
input.getRev()->to_string(Base16, false));

Headers headers = makeHeadersWithAuthTokens(host);
Expand All @@ -366,9 +371,11 @@ struct GitLabInputScheme : GitArchiveInputScheme
void clone(const Input & input, const Path & destDir) const override
{
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
auto owner = boost::replace_all_copy(getStrAttr(input.attrs, "owner"), "/", "%2F");
auto repo = boost::replace_all_copy(getStrAttr(input.attrs, "repo"), "/", "%2F");
// FIXME: get username somewhere
Input::fromURL(fmt("git+https://%s/%s/%s.git",
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
host, owner, repo))
.applyOverrides(input.getRef(), input.getRev())
.clone(destDir);
}
Expand Down
9 changes: 9 additions & 0 deletions src/nix/flake.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ Currently the `type` attribute can be one of the following:

* `gitlab:veloren%2Fdev/rfcs`

However, if using Attribute set representation slashes are permitted as the ``repo`` value:
```nix
inputs.nixpkgs = {
type = "gitlab";
owner = "gitlab-org";
repo = "release/tasks";
};
```

* `sourcehut`: Similar to `github`, is a more efficient way to fetch
SourceHut repositories. The following attributes are required:

Expand Down