Skip to content
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

nixfmt-tree: refactor impl to use treefmt.withConfig #391319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MattSturgeon
Copy link
Contributor

Follow up to #390147 and #384857, this PR refactors the new nixfmt-tree package to make use of the new treefmt.withConfig wrapper.

This is technically a breaking change:

  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.

There are also non-breaking changes:

  1. runtimePackages was renamed to runtimeInputs. For consistency with treefmt.withConfig and other parts of nixpkgs, such as writeShellApplication.
  2. Added a warning when runtimeInputs is overridden to a list without a nixfmt package. In such cases, users should probably just use treefmt.withConfig.

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 to treefmt.withConfig. In hindsight, it also feels like a bit of a leaky abstraction?

cc @infinisil @NixOS/nix-formatting

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

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. `runtimePackages` was renamed to `runtimeInputs`. For consistency
   with `treefmt.withConfig` and other parts of nixpkgs, such as
   `writeShellApplication`.
2. Added a warning when `runtimeInputs` is overridden to a list without
   a nixfmt package. In such cases, users should probably just use
   `treefmt.withConfig`.
Copy link
Member

@infinisil infinisil left a 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.
Copy link
Member

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 :)

@wegank wegank added 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package 12.approvals: 1 This PR was reviewed and approved by one reputable person labels Mar 20, 2025
@MattSturgeon
Copy link
Contributor Author

Any objections to getting this merged @NixOS/nix-formatting ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10.rebuild-darwin: 1-10 10.rebuild-darwin: 1 10.rebuild-linux: 1-10 10.rebuild-linux: 1 12.approvals: 1 This PR was reviewed and approved by one reputable person 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants