-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
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!
@@ -62,7 +80,7 @@ buildEnv { | |||
``` | |||
|
|||
You can then also use `treefmt` in a pre-commit/pre-push [Git hook](https://git-scm.com/docs/githooks) | |||
and `nixfmt` with your editors format-on-save feature. | |||
and with your editor's format-on-save feature. |
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 ? |
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
|
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-tree
package to make use of the newtreefmt.withConfig
wrapper.This is technically a breaking change:
settings
will no longer entirely replace all settings, instead settings are now merged as modules.nixfmt
) available on the PATH, only the wrappedtreefmt
will be added to the shell's PATH.There are also non-breaking changes:
runtimeInputs
, for consistency withtreefmt.withConfig
and other parts of nixpkgs, such aswriteShellApplication
.nixfmtPackage
to allow specifying a different nixfmt package, without having to know to overridenixfmt-rfc-style
.runtimePackages
with 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 = relaxed
sandbox = true
nix-build -A nixfmt-tree.tests
nix-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.