Fix and Improve Flakeref for Gitlab repos.#9163
Fix and Improve Flakeref for Gitlab repos.#9163Silver-Golden wants to merge 2 commits intoNixOS:masterfrom
Conversation
|
Triaged in Nix team meeting:
|
|
No worries about the swiftness, its a big enough change but it should help solve a host of issues |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-10-27-nix-team-meeting-minutes-98/34695/1 |
f9f491d to
42f93c0
Compare
|
@roberth Rebased it with the recent changes to Again, I am not all that great with c++ but hopefully its grand. |
|
Rebased yet again. |
|
Needs user-facing docs and release notes. |
roberth
left a comment
There was a problem hiding this comment.
I'm concerned that this will put many flake authors in an impossible dilemma between supporting newer or older nix.
This is probably only the top of the iceberg because gitlab is often used as a private instance. sourcegraph query
Perhaps we could accommodate these users by adding a retry logic to the actual fetcher, to reinterpret its arguments, to recover the original intent?
Also concerning is that we don't have a VM test for gitlab fetching. Or any test at all really.
We could borrow the setup from the gitlab test in NixOS.
src/libfetchers/github.cc
Outdated
| auto owner = std::regex_replace(getStrAttr(input.attrs, "owner"), std::regex("/"), "%2F"); | ||
| auto repo = std::regex_replace(getStrAttr(input.attrs, "repo"), std::regex("/"), "%2F"); |
There was a problem hiding this comment.
It seems that it would be better to use a general percent encoding function here and in similar calls below.
There was a problem hiding this comment.
As in create a new function to replace it the %2F?
Or would ye know of an already existing one I can use?
src/libfetchers/github.cc
Outdated
| // FIXME: get username somewhere | ||
| Input::fromURL(fmt("git+https://%s/%s/%s.git", | ||
| host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"))) | ||
| Input::fromURL(fmt("git+https://%s/%s/%s.git", host, owner, repo)) |
There was a problem hiding this comment.
(non-blocking) This shouldn't have to go through fromURL, but this could be a separate issue.
There was a problem hiding this comment.
That is how it is already
Line 384 in f018048
I did not know enough to make changes to it, only extracting out the owner/repo.
What should it be doing instead?
Why is that? |
Kinda is that way already. |
|
The sourcegraph is interesting (when ye expand the search), most are for the mailserver (which we also use) and only two are using Semi random thought, kinda a hack. Ye would end up with two schemes for gitlab, one with github style, and one gitlab style but it wouldnt break any existing flake. (Hopefully this isnt a fever-dream idea since its something like 3am for me) |
|
This issue has been causing chaos for me at work, where we use GitLab. Is there anything that I can do to help move this PR along? What else needs to be done? |
|
shy bump 😅 Or: is there a workaround for flake inputs from repos in subgroups that I can use in the meantime? 🤔 |
Workaround is: this name_of_item = {
type = "gitlab";
host = "gitlab.example.com";
owner = path%2Fto";
repo = "repo";
};This would be |
|
@roberth @edolstra (or anyone else), can resolving this please be prioritized? I'm willing to help if there's anything I can do. Devs at my work use NixOS with a shared module that's in a GitLab subgroup, so we have a ton of Nix flake repos that are broken by this bug. We've been pinning nix to 2.17 to avoid this bug, but now that's problematic due to CVE-2024-27297. Now we're stuck between a rock and a hard place of either being insecure or needing to change the input style on ~100 repos. |
Gitlab expects the repository path to be percent-encoded in the API
Contrary got GitHub or other forges, GitLab allows nested organisation (`gitlab.com/foo/bar/baz`). This means that we must treat GitLab urls differently as we can't assume that `gitlab.com/foo/bar/baz` means “the `baz` revision of the `foo/bar` repository”. Instead make it mean “the `baz` repository in the `foo/bar` organisation” and require passing the ref or rev via a query string.
|
Just gave this a look. I had to tweak it a bit because it wasn't working any more on master. Also deduped things a bit to make the diff smaller (I hope). The current iteration seems correct (@roberth I'll let you have a second pass on this to confirm). I'd also like to emphasise @roberth 's command above:
Anyone caring about proper GitLab URL support: please consider contributing that. I don't think anyone from the maintenance team will have the bandwidth for it in a foreseeable future, and that's absolutely critical to keep it properly supported. |
|
(Urgh apologies @Silver-Golden , I naively force-pushed after rebasing, forgetting that this wasn't my branch. Let me know if you want me to revert the changes and merge them more nicely with your existing work) |
|
@thufschmitt as long as it works it will be grand. On a related note I have been musing more on #9163 (comment) ( |
|
IIUC it doesn't have to be |
| GitLab allows to nest organisations (`gitlab.com/org/suborg/subsuborg/repo`). | ||
| The flakeref URL for GitLab repositories now supports that. | ||
|
|
||
| This means that it isn't possible any more to use the `/<ref>` (or `/<rev>`) syntax for GitLab repositories (as that would be ambiguous), and users need to pass an explicit query parameter (`?ref=<ref>` or `?rev=<rev>`). |
There was a problem hiding this comment.
There's precedent in other tools for //<ref>.
If we don't implement that, I think we should explicitly deny it, to avoid confusion and perhaps allow it later.
Relevant notes: #8773 (comment)
Less critically, we may also consider supporting /<rev>, as full revs are easily distinguished by their length and hex characters.
|
As a normal Nix user that stores all of his flakes on GitLab, I'd love to have Having |
|
While the workaround of manually encoding the "subgroup" slash as %2F works for nix, this causes other tools to fail that read the lock file, as git itself doesn't handle URL encoding. In my case this cases renovate to fail, after renovatebot/renovate#31921 was merged. Is there anything that I could in order to get this fix merged? CC: @SuperSandro2000 |
Do to a bug in nix one needs to uri encode the owner of a gitlab repository that resides in a subgroups, in this case the `/` as `%20F`. This however breaks the `git ls-remotes` which renovate runs to discover if the input can be updated. This commit passes the owner attribute through `decodeURIComponent` to ensure that `git` is unware of this workaround on nixs side. Nix PR: NixOS/nix#9163
|
I think this has stalled because of concerns of breaking changes. I think to unblock this we can proceed to:
nix/src/libflake-tests/flakeref.cc Lines 230 to 243 in 34bca92
|
Motivation
Fix the broken input url's and improve the flake input url and attribute set for Gitlab
Context
The original goal of #8773 (and then #9160) was to remove the need for using
%2Feverytime a/was encountered.This was limited to just the attribute set because it was using the Github format to parse the url.
Without anything else happening I would have kept with that particular pull request.
#6614 was the nudge that changed things.
Its purpose was to change all teh percent encoded characters (
%2F) into the actual character they represented.However this broke Gitlab URL's (#9161) due to the fact that Github has
owner/repo/branchbut Gitlab can haveGroup/SubGroup1/SubGroup2/RepoThe move to create
GitlabLikeInputSchemeandGithubLikeInputSchemewas inspired by @roberth 's comment:The change made was for both to inherit from
GitArchiveInputSchemeto avoid duplication.My implmention does cause a breaking change in that anyone using the last part of the url for the ref/rev will need to change their input to use
?ref=/?rev=.Group%2FSubGroup/Repo/Rev->Group/SubGroup/Repo?rev=RevGroup%2FSubGroup/Repo/Ref->Group/SubGroup/Repo?ref=RefThis is because it is virtually impossible to determine if the last segment is repo/ref/rev without calling the Gitlab API.
Due to the current state of all gitlab URL's (with subgroups) being broken I believe that this is a worthwhile change.
Especially since users are already used to using
?host=if they use a selfhosted gitlab instance, getting them to use?ref=/?rev=and being explicit shouldn't be too difficult.Some discussion can be found here: #8773 (comment)
Tests could be a good thing to add, however I don't have the skills myself for that (still new to C++).
This patch supersedes #8773.
This patch should close out #9161 on completion.
Priorities
Add 👍 to pull requests you find important.