diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 80598e7f836..f9eeef331fb 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -11,6 +11,7 @@ #include #include #include +#include namespace nix::fetchers { @@ -332,9 +333,10 @@ struct GitLabInputScheme : GitArchiveInputScheme Hash getRevFromRef(nix::ref store, const Input & input) const override { auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com"); + auto repo = std::regex_replace(getStrAttr(input.attrs, "repo"), std::regex("/"), "%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, getStrAttr(input.attrs, "owner"), repo, *input.getRef()); Headers headers = makeHeadersWithAuthTokens(host); @@ -355,8 +357,9 @@ 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 repo = std::regex_replace(getStrAttr(input.attrs, "repo"), std::regex("/"), "%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, getStrAttr(input.attrs, "owner"), repo, input.getRev()->to_string(Base16, false)); Headers headers = makeHeadersWithAuthTokens(host); @@ -366,9 +369,10 @@ struct GitLabInputScheme : GitArchiveInputScheme void clone(const Input & input, const Path & destDir) const override { auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com"); + auto repo = std::regex_replace(getStrAttr(input.attrs, "repo"), std::regex("/"), "%2F"); // FIXME: get username somewhere Input::fromURL(fmt("git+https://%s/%s/%s.git", - host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"))) + host, getStrAttr(input.attrs, "owner"), repo)) .applyOverrides(input.getRef(), input.getRev()) .clone(destDir); } diff --git a/src/nix/flake.md b/src/nix/flake.md index 92f477917fd..d9d63bee0dc 100644 --- a/src/nix/flake.md +++ b/src/nix/flake.md @@ -277,6 +277,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: