Improve Flakeref for Gitlab repos.#8773
Conversation
roberth
left a comment
There was a problem hiding this comment.
The change in behavior is good. Arguably the repo attribute should be in terms of the gitlab "domain", which means it's a path with /s.
I'm not so sure about the overall implementation, but that's a pre-existing tech debt that we don't have to resolve right away - ie use a URL library or such. Afaic, we can merge this after resolving the std vs boost question.
| auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com"); | ||
| 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", |
There was a problem hiding this comment.
Why are we constructing urls with string concatenation 🤦
There was a problem hiding this comment.
The value of repo has to go into the url encoded, one way or another.
Currently people are manually encoding it for example: build%2Fomnibus-mirror%2Falertmanager.
The goal of this change is to allow both build%2Fomnibus-mirror%2Falertmanager and build/omnibus-mirror/alertmanager
src/libfetchers/github.cc
Outdated
| #include <optional> | ||
| #include <nlohmann/json.hpp> | ||
| #include <fstream> | ||
| #include <boost/algorithm/string/replace.hpp> |
There was a problem hiding this comment.
Why not just std::string's replace?
There was a problem hiding this comment.
I did try using that initially.
The main problem i hit there was it can only replace a char with another char.
It does not work when you try to replace a char with a string.
Should I adjust it so that both the owner and repo can take slashes? So that would give users the flexability of all these: example1 = {
type = "gitlab";
owner = "gitlab-org";
repo = "build/omnibus-mirror/alertmanager";
};
example2 = {
type = "gitlab";
owner = "gitlab-org/build";
repo = "omnibus-mirror/alertmanager";
};
example3 = {
type = "gitlab";
owner = "gitlab-org/build/omnibus-mirror";
repo = "alertmanager";
}; |
|
Just viewed yer profile and realised I should have mentioned ye @roberth |
Right, I think framing it as "repo has a path" was a bit wrong. To be correct about it, in the GitLab data model we have: In Nix we have: So a slash in a I guess for gitlab it would have made more sense to have a single attribute for the whole path to the repo including the "owner" - whatever that means in a gitlab context. We shouldn't be making up such terms. |
|
I see what ye mean, you would be thinking more of Where things get tricky is ownship in Gitlab is a lot more nuanced than the flat structure of Github. We have https://gitlab.skynet.ie/compsoc1 which as two groups, the computer society and skynet (social vs technical). For https://gitlab.skynet.ie/compsoc1/skynet/nixos I would consider this the attribute nixos = {
type = "gitlab";
owner = "compsoc1/skynet";
repo = "nixos";
};Which is in line of what ye are thinking of, however I would consider https://gitlab.skynet.ie/compsoc1/skynet/website/2023 to be like so: website = {
type = "gitlab";
owner = "compsoc1/skynet";
repo = "website/2023";
};In both cases I consider (Semi serious, |
As in something useful that we tend to take for granted? Interesting.
Right! And this is not really represented in their data model. That means we won't agree on what the split should be and we should simplify the interface so that we don't burden users with coming up with their own ownership ideas where it doesn't really apply unambiguously. <Insert seizing means of production communism joke here.> But seriously, we should probably get rid of @edolstra, would it be ok to have an attribute called |
|
Yes, |
|
Maybe we should just keep |
|
It wasnt the intention of mine earlier but I am more in favor of allowing slashes in both |
|
Ye, I would be quite happy with this # top level group is "owner"
nixos = {
type = "gitlab";
owner = "compsoc1";
repo = "skynet/nixos";
};
# subgroup is "owner"
nixos = {
type = "gitlab";
owner = "compsoc1/skynet";
repo = "nixos";
};
# no owner
nixos = {
type = "gitlab";
repo = "compsoc1/skynet/nixos";
}; |
That'd be my preferred syntax, and if we do keep the I don't think libfetchers is set up to normalize the attributes and remove |
|
Why lock it down to a specific one though? If its about making it easier for the user then any of those will be better than what we have now. Especially easier to fit in than a new attribute. |
|
I'm mostly ok with accepting multiple input syntaxes, but not happy about propagating that entropy into the rest of a Nix expression. So what I'm suggesting is for |
|
@roberth I can see where ye are coming from, however that is an already existing problem. Currently I could have it like so: nixos = {
type = "gitlab";
owner = "compsoc1";
repo = "skynet%2Fnixos";
};
nixos = {
type = "gitlab";
owner = "compsoc1%2Fskynet";
repo = "nixos";
};So if you try to override the repo without also overriding the owner ye may run into issues. And as far as I can tell there has been no issue raised in the three years since the lines were last touched. Pushed up a commit to also allow slashes in @edolstra have you any thoughts on the convo above? |
|
Triaged in the Nix team meeting
Scratch space:
Decision: Will discuss further |
|
@Ericson2314 thanks for discussing it in the meeting. |
It's related but can be considered separately. The team hasn't made a decision about the URL yet, so I'd focus on just the structured data syntax. Possible migration path for URLs We could just break it, or do a migration. For a migration plan we only need to consider the user facing interface, but that's not to say that the implementation will be easy.
1-3 are a good goal for 23.11 So if we want to do a user friendly migration for the flakeref URIs it will take a while. Flakeref URIs are just a nice to have for the flakes feature, so we could stabilize flakes before stabilizing the URIs. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-08-18-nix-team-meeting-minutes-80/32081/1 |
|
Reviewed in Nix team meeting 2023-08-21:
|
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-08-21-nix-team-meeting-minutes-81/32082/1 |
|
Not sure if its intended but it seems the way the URL is handled has changed. If ye want I could split this off into a new ticket. This worked fine on 2.13.2 at least, not sure what was last version it worked on. If I change the last slash in it to and for funsies use all |
|
@Silver-Golden yes, that's been an intentional change here #6614 |
|
Welp, once again it feels that gitlab is not even a second class citizen :( This most likely means that it will require a rewrite of the |
Still a bug though. #6614 should be re-done by factoring out the parser, putting the freshly parsed strings into a struct and adding a bunch of unit tests. I don't know how people can accept custom parsing code without a ton of tests. This is insane. Another thing that needs to happen is that the gitlab code should stop inheriting any code that makes github assumptions. |
|
@roberth I am planning to open a new issue ticket and merge request to fix the new bug introduced above, anything in particular from this one do ye want me to add? |
|
@Silver-Golden I think that's a problem in the parsing/decoding logic, which wasn't really touched by this PR. |
|
Switching over to #9160 for this PR. |
Motivation
Gitlab has the option to have repos inside folders for example: https://gitlab.com/gitlab-org/build/omnibus-mirror/alertmanager
Under the current system (docs) we would have to use
or
Context
I first encountered the problem myself in #6435 where I learnt about teh work around and that got me going for that time.
My university's computer society is now using Gitlab and NixOS for our servers and I can foresee that using
%2Fwill cause some issues for folks being trained/taught NixOS.Also I think it looks ugly AF (that alone should be enough reason to fix it).
My ideal solution would have been to allow slashes in the
example.urlabove, however due to #4061 it could cause breaking changes for any flake using the current implementation.So as a result I am targeting the attribute directly.
In the
github.ccevery/in therepofield will get replaced with a%2f, maybe not the best but it is functionalIf there is a better way for doing it please let me know.
I added to the docs as well, not 100% sure its the ebst placement but I figured it was best to keep it close to where teh original mentioned the workaround.
I built nix and tested the changes locally (in wsl) and it works for my example above.
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.shsrc/*/teststests/nixos/*Priorities
Add 👍 to pull requests you find important.