-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Treewide Nix reformat pass 1 [skip treewide] #322537
Conversation
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/formatting-team-meeting-2024-06-25/47661/1 |
I'd say we should block on NixOS/nixfmt#153. There are also many issues about either awkward formatting result or implementation correctness. It's no good to race reformatting everything before that.
This sounds too long to me. If the whole-repo checking takes too long, it blocks auto-checking in git commit hook. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-57/47823/1 |
@oxalica The reason I'm pushing for this is because there's a lot of churn from people reformatting individual parts on their own, @mweinelt can attest to that. Let's not let perfect be the enemy of good, the formatter works and is unlikely to change drastically. We should definitely block on correctness bugs like NixOS/nixfmt#197 though, this is being worked on :) Regarding the time it takes for a full format, the solution I'd propose is to use a pre-commit hook that only formats files that were changed. This also nicely aligns with CI only requiring changed files to be formatted. I'd be okay with blocking on that for this PR, I'll add it to the TODO items. In addition to that, if CI fails, it shows the Alternative: treefmtOne could also imagine using treefmt because it caches results, but this will be slightly problematic when we change the formatter in the future and need to do the same multi-pass approach to avoid merge conflicts. There's going to be times when not the entire codebase is formatted in the same way, and treefmt would mess that up. |
That's kinda non-trivial to me, and you need to retrieve file list from Also I opened NixOS/nixfmt#211 for tracking this. |
Since it's the pre-commit hook, we only have to worry about the single commit that is being made, so I don't think it will be bad, but I'll see it when I try 😆. And we can use a |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
The good thing here is we can skip formatting if something weird really happens, because it doesn't make subsequent CI check fail. |
I’d like to recommend a Another advantage is that tools like If you need any help writing an efficient and correct Git hook for this, please ping me. |
a22dc49
to
a826121
Compare
174e6e4
to
00d4895
Compare
To make this PR easier to review, I split off the enforcement for new files into #326407. So this PR is only for the treewide format now! Also note:
|
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \ --argstr baseRev b32a094 result/bin/apply-formatting $NIXPKGS_PATH
ff8b477
to
4f0dadb
Compare
…ng{,-next} By committing all of these together on master, we don't need to deal with a merge conflict of this file once staging/staging-next is merged together.
I walked through the methodology of this work with ~12 people in the merge party call, no complaints, merging! 🎉 |
…next The "reformat everything on master/staging/staging-next together" approach from NixOS#322537 didn't quite work out: master now can't be automatically merged into staging-next anymore (same for staging-next into staging). To resolve this, we're performing two merges: - This first one to merge the commit on master just before the treewide reformat into staging-next - The following one to merge the treewide reformat commit into staging-next, but effectively ignoring all changes from the treewide reformat commit
…next The "reformat everything on master/staging/staging-next together" approach from NixOS#322537 didn't quite work out: master now can't be automatically merged into staging-next anymore (same for staging-next into staging). To resolve this, we're performing two merges: - The first one (see parent commit) to merge the commit on master just before the treewide reformat into staging-next - This one to merge the treewide reformat commit into staging-next, but effectively ignoring all changes from the treewide reformat commit using `-X ours` when merging (and manually handling the few edge cases)
Turns out the "reformat everything on master/staging/staging-next together" approach didn't quite work out: master couldn't be automatically merged into staging-next anymore (same for staging-next into staging). Thanks to @wegank for taking care of fixing that by manually doing the staging merge! |
Thanks to the works of inspired, motivated and provided individuals, we can has nice things! Thanks, everyone involved! |
I have about 350 local patches against |
There's this which might help: #363759 |
If these are generally applicable patch sets, can I suggest that they be sent to nixpkgs? This could have been avoided that way:
|
Ended up doing the following: # 1. Create empty commit:
git commit --allow-empty -m "EMPTY commit: will absorb relevant formatting changes"
# 2. Move the empty commit to queue beginning:
git rebase -i --keep-base
# Move "EMPTY commit: will absorb relevant formatting changes" entry from last line to the first line.
# 3. Get affected formatted files. Pick the commit from `.git-blame-ignore-revs` for the relevant branch. For `staging` it is `667d42c00d566e091e6b9a19b365099315d0e611`
FORMATTED_FILES=$(git diff --name-only 667d42c00d566e091e6b9a19b365099315d0e611^..667d42c00d566e091e6b9a19b365099315d0e611 -- $(git diff --name-only origin/staging...staging) | tr $'\n' ' ')`
# 4. Reformat:
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --tree-filter "nixfmt $FORMATTED_FILES" -- $(git merge-base origin/staging staging)..
...
Rewrite 6fc0a951e9b7a7e3f80628ca0a6c4c9f54fd2dd6 (56/327) (65 seconds passed, remaining 314 predicted)
...
Rewrite c20df82da66da6521f355af508bfedc047cffa64 (326/326) (1183 seconds passed, remaining 0 predicted)
Ref 'refs/heads/staging' was rewritten
# 5. Rebase past the reformat (as one would normally do the update):
git rebase -i
# Done |
This is the next step towards accepted NixOS/rfcs#166 after #322512 and #326407, see also #322520 and NixOS/nixfmt#153 🎉.
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of NixOS/rfcs#166.
Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts.
A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted.
The @NixOS/nix-formatting will approve/merge this PR.
Verification
The reformatting commit is fully auto-generated by the code in https://github.com/infinisil/treewide-nixpkgs-reformat-script, see the commit message on how to do a complete verification.
Things done
nix-instantiate --parse
doesn't change (add--arg check true
to the verification build to do that, takes a bunch longer)src = ./.
entries that unintentionally include their own.nix
files #301014)This work is sponsored by Antithesis ✨
Add a 👍 reaction to pull requests you find important.