-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
nixfmt-tree: refactor impl to use treefmt.withConfig
#391319
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
Conversation
infinisil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah so this was the original motivation for including the formatter binaries as well, but as explained in the last formatting team meeting, people should be using treefmt even for format-on-save, because treefmt knows about the options you format the codebase with :)
|
Any objections to getting this merged @NixOS/nix-formatting ? |
jfly
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thought for you inline. I trust your decision either way.
e4741ac to
afedaef
Compare
Refactor the new `nixfmt-tree` package, to make use of the new `treefmt.withConfig` wrapper. Breaking changes: 1. Overriding `settings` will no longer entirely replace all settings, instead settings are now merged as modules. 2. Adding the package to a nix shell will no longer make runtime inputs (such as `nixfmt`) available on the PATH, only the wrapped `treefmt` will be added to the shell's PATH. Non-breaking changes: 1. Introduced `runtimeInputs`, for consistency with `treefmt.withConfig` and other parts of nixpkgs, such as `writeShellApplication`. 2. Introduced `nixfmtPackage` to allow specifying a different nixfmt package, without having to know to override `nixfmt-rfc-style`. 3. Deprecated `runtimePackages` with a warning. Use the new args instead.
afedaef to
a1bf64c
Compare
|
|
Based on @jfly's feedback, I've reworked the I introduced a The (old) The final If a user explicitly overrides |
jfly
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I was surprised to see the binary name "nixmt" still hardcoded in this PR, rather than using lib.getExe, but IIUC, it has to be this way for backwards compatibility. I believe this can get cleaner in the future when we drop support for backwards compatiblity.
Thanks for iterating on this!
Currently we're running Not adding nixfmt to the PATH and instead configuring its absolute path (via |
No, let's merge this. We can revisit this in the future when we drop the deprecated codepath. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/formatting-team-meeting-2025-04-01/62524/1 |
|
@MattSturgeon could this be backported to 24.11? EDIT: oops I meant #390147, but this would also be good. Also thinking about it more the branch off of 25.05 is in only a few days so it probably doesn't make sense to do a significant backport like this. Basically what I'm saying is ignore this. |
Follow up to #390147 and #384857, this PR refactors the new
nixfmt-treepackage to make use of the newtreefmt.withConfigwrapper.This is technically a breaking change:
settingswill no longer entirely replace all settings, instead settings are now merged as modules.nixfmt) available on the PATH, only the wrappedtreefmtwill be added to the shell's PATH.There are also non-breaking changes:
runtimeInputs, for consistency withtreefmt.withConfigand other parts of nixpkgs, such aswriteShellApplication.nixfmtPackageto allow specifying a different nixfmt package, without having to know to overridenixfmt-rfc-style.runtimePackageswith a warning. Use the new args instead.We could have it so that runtime inputs still end up being installed to
$out/bin/, but this would negate much of the advantage of delegating most impl-details totreefmt.withConfig. In hindsight, it also feels like a bit of a leaky abstraction?Fixes #395045
cc @infinisil @NixOS/nix-formatting
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-build -A nixfmt-tree.testsnix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.