-
-
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
Enforce nixfmt on new files and changed files that were already formatted #326407
Enforce nixfmt on new files and changed files that were already formatted #326407
Conversation
This makes the Nix format workflow check new/changed files instead of just an allowlist. This enforces that all PRs updated after this is merged are required to have fully standard formatted Nix files!
Shouldn't this be the other way round? First, nixfmt is enforced for new/changed files, then the treewide PR is merged? |
@Pandapip1 If we first require all new/changed files to be formatted without doing the treewide format, anybody branching off master would have to format all of the files they're touching to make their PR valid. The other way around is also not entirely great, because we shouldn't merge PRs that mess up the newly-formatted files either. Really, these two PRs should be merged around the same time so that both of these problems can be avoided. Splitting it into two PRs is mainly done to make reviewing easier, because the other one is so big (and entirely automated), whereas this one is more tricky. |
Oh, just noticing a problem: If we start doing this, we need to have My proposed solution to this is to change this PR to enforce formatting of changed files only if they were previously formatted already, so that e.g. it wouldn't be enforced for all files that aren't part of the treewide reformat, including Edit: Now implemented, this makes this PR way more independent of the original one, there's no more need to merge them together :) |
The next commit will use this to have a simpler change
This prevents situations where contributors need to suddenly format a huge file even if they only changed a small part of it (e.g. all-packages.nix)
6ff7c81
to
8bbfb0b
Compare
EDIT:
Great minds think alike, lol. +1 to this solution. |
I think NixOS/nixfmt#179 may block this and #322537, because the e.g: nixpkgs/nixos/tests/switch-test.nix Lines 8 to 10 in 0bf815b
|
@MattSturgeon This isn't relevant for this PR, since it wouldn't enforce formatting on files that have |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/formatting-team-meeting-2024-07-23/49510/1 |
This comment was marked as resolved.
This comment was marked as resolved.
Are you doing this in the nix shell introduced in #322512? That should provide a Also, just to eliminate the obvious, are you running the command from the right location for those relative paths? |
I actually didn't use the |
In most cases there should be no tangible difference, afaik. However in some cases the version used by the shell (and CI) may be different to the version in nixos-unstable. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-to-use-nixfmt-for-nixpkgs/56590/2 |
Description of changes
This is a big step towards full implementation of NixOS/rfcs#166, see also NixOS/nixfmt#153. This is split off from #322537 (the first big treewide reformatting), because there's no need to have it be in the same PR. This PR should be reviewed/merged by the @NixOS/nix-formatting team.
This PR makes the Nix format workflow check all new files and changed files (that were already formatted) to be formatted.
Things done
This work is sponsored by Antithesis ✨
Add a 👍 reaction to pull requests you find important.