-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically formatting nixpkgs #120832
Comments
Discourse topic https://discourse.nixos.org/t/formatting-rules-for-nixpkgs/2233. |
There is also definitely something to be said for re-formatting all at once. It would make it easy to have an EDIT: The commit message for the reformat commit should probably explain "hey, if you're seeing this commit pop up in |
I think the original reason for bringing this up was due to nitpicky formatting requests pushing away new contributors. Personally, I see there being two options:
One challenge with the latter option is that the definition of "nitpick" is not very clear. Personally, I'm a fan of the "explicit over implicit" rule, so I would be in favor of a linter, but I understand the difficulties that would create with things like |
I think that could be done by adding a GitHub workflow |
I'm in favor of ripping off the bandaid, formatting everything, and starting a ignore revs file. We'd need to simultaneously reformat all of stable if we wanted to backport things. I've written a tool rebase a branch on top of a branch where the target branch was automatically formatted. It needs work, but is available as an answer for how to deal with existing PRs: https://github.com/grahamc/git-rebase-format |
A good time to reformat would then be just before 21.05 branch off. It seems we agree with a single point in history to format things. Does someone have time to test & prepare for formatting to happen on May 21st? cc @jonringer |
I'm all in favor of this. I would prefer to do this before zhf and cause issues for contributors, which is a week away. |
@jonringer the problem with doing it before is that it would make existing PRs conflict, wouldn't it be better to do it just before a new branch is formed? Why do you think that's better? |
Do we even know which tool we're going to bless yet? |
Does that mean we consider the current state of |
I'd like to get us to commit to doing it first, then we (take a limited amount of time to) pick the tool. I think details can be figured out, the tooling will evolve, we can exclude things that break, etc. |
I guess if the strategy is to format all files, waiting until branchoff is also fine. There's just more risk of delaying a release if a regression gets introduced. And changes of that scale make it difficult to capture regressions. Which is why I had a preference to do it before zhf. But if the refactoring is done on another branch, and we're confident about it, then I'm okay with that as well. |
I'm willing to take that risk by volunteering to fix issues if they happen between branch-off and release, related to formatting. |
|
|
I created a proof-of-concept to automatically format pr's, feel free to use and modify as needed: |
Nice! Feedback:
|
I do get a prompt to manually approve this in the webinterface.
Wouldn't that just be
Agreed! |
What are your opinions on something like https://github.com/reviewdog/reviewdog? It looks like it can create an actual GitHub review from the lint output complete with suggested fixes. It can work with diff, so you can just run I think this is less intrusive than actually committing to the PR. |
I don't know, ideally this shouldn't actually do anything on most PRs because people have nixpkgs-fmt setup to automatically trigger before they submit the PR. It's definitely worth considering tho! |
I just know that a lot of times I'll accidentally push an unformatted commit and quickly follow it up with a correctly formatted one. I don't want my second push to be a conflict with the automated bot. |
@FRidh I started adding I'm not sure if I'll be able to catch them all though, and feedback is very welcome, before I spend too much time on it. |
Wrong link, should be #121306 |
Love the progress so far, keep it coming 🙌 |
Status update: I got a Shown here: This uses |
If we decide on sticking with |
I have pinned nixpkgs to a specific revisions due to concerns expressed by @domenkozar (#120832 (comment)) |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/formatting-rules-for-nixpkgs/2233/8 |
This may be something that is resolved by now, or doesn't apply in this context, but I recalled seeing an assertion in IRC semi-recently that nixpkgs-fmt may perpetually reformat some files. It looks like the ~proof was https://github.com/Kiwi/lol-nix-formatter/commits/master/apache.nix but you can see the conversation as well: |
@abathur the apache file formats nicely for me on 1.2.0. This file has some syntax problems ( Would be really good to follow-up on it though, to ensure nixpkgs-fmt is behaving correctly. |
That's another solution. I'm just not as big of a fan when it comes to pinning. Generally this introduces additional friction when trying to update processes. |
I think this deserves a lot more attention. Maybe we could gradually migrate the packages by doing one folder a time and merge it in smaller batches. |
There is an ongoing RFC for this at NixOS/rfcs#101. |
Related: NixOS/rfcs#166 and (perhaps this is superseded by) NixOS/nixfmt#153 |
This is being worked on, check out #322520 for future tracking :) |
IIRC this was brought up a few times on IRC, but I don't know of any existing issue. However:
callPackage ./. {}
vscallPackage ./. { }
.#nixos-dev
(IIRC) it was agreed that if we establish a formatter, it should be primarily used on new packages. Apart from the fact that formatting makes backports usually harder (because you'll run into way more merge conflicts), my experience is that most formatters (to be fair, I have to take a way closer look at bothnixfmt
andnixpkgs-fmt
, but from what I've seen we'll have the problem here as well) make it harder togit blame
a file. Despite the IMHO problematic name I generally use this to understand why a line of code looks the way it does when I don't understand it entirely.So what I want to say is, if we start using a formatter, I personally think that we should be careful with applying it to existing code.
Originally posted by @Ma27 in #118661 (comment)
The text was updated successfully, but these errors were encountered: