All files will be formatted using a pinned version the official Nix formatter, aka pkgs.nixpkgs-rfc-format. CI will enforce this going forward, ensuring that all files continue to be formatted consistently.
Inside Nixpkgsā nix-shell/nix develop, you will be able to run treefmt to get the right formatting on all files. You can also use this with a pre-commit/push Git hook or your editorās auto-format-on-save feature!
We are coordinating asynchronously on Matrix and will hold a final review and merge party at 2025-04-01T18:00:00Z in this Jitsi, feel free to join both!
If you have questions, concerns or problems, let us know here, in the Matrix room, in the nixfmt issue tracker or ping @NixOS/nix-formatting in Nixpkgs.
Note that the formatter is still being worked on, so we appreciate any support and could use some more Haskellers!
Merge conflicts
This PR will lead to merge conflicts for a number of PRs. Hereās two ways which will usually work to resolve formatting conflicts automatically.
Method 1: Auto-rebase script
You can use the new auto-rebase script. This takes some time to run (especially if you have a lot of commits in your PR), but should take care of rebasing the current branch while automatically resolving any merge conflicts caused by the full Nixpkgs reformat:
This method has a bug (see Mergetool fixes by infinisil Ā· Pull Request #291 Ā· NixOS/nixfmt Ā· GitHub for the fix, though it will take some time for it to be propagated) that can affect merge correctness. As such, it is not recommended right now. If you use it regardless, make sure to double-check the result for correctness.
Instructions
Nixfmt newly provides a mode usable by git mergetool that is faster and more general than the above, and allows resolving almost all formatting-related conflicts automatically.
Thereās more extensive docs, but the most basic way to use it is as follows:
# Run these once:
git config mergetool.nixfmt.cmd 'nixfmt --mergetool "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
git config mergetool.nixfmt.trustExitCode true
# Run these to rebase:
git rebase master
git mergetool -t nixfmt .
In other news: pkgs.nixfmt-tree
Not directly related to the above, we want to also highlight that thereās a new pkgs.nixfmt-tree package, which is a convenient wrapper around nixfmt-rfc-style and treefmt, making it straightforward to integrate into nix fmt, nix-shell or nix develop for your personal projects.
Speaking as just @infinisil now, this will be one of my last efforts for Nix formatting, as I plan to step down from the team soon in order to focus on my new responsibilities as a NixOS Foundation member. It has been a joy to work with the other members, and Iām looking forward to seeing the gears turning without my involvement!
To close this chapter, I feel the need to give another huge shout-out to Antithesis and Tweag. Theyāve enabled me to spend time on this for over three years now, thank you!
Weāre on schedule to merge this tomorrow! I messed up the times a little bit all over the place, so just to clarify: We meet 2025-04-01T18:00:00Z in this Jitsi for the merge party
Thanks for the detailed post, and the wonderful work on this! Much appreciated.
Are there any detailed, recommended instructions on how to set this up? treefmtās README mentions nixpkgs-fmt which is considered deprecated of course in favor of nixfmt-rfc-style.
Maybe we should suggest people to use https://pre-commit.com/ somehow? Iām not very experienced with Git Hooks and with https://pre-commit.com/ in particular, but I think itād be helpful for everyone to get some guidance maybe?
One thing this is especially nice when setting this up in projects is to use flake-parts which has integration with the mentioned tools treefmt-nix and git-hooks.nix. Personally I wrapped up these tools that I use in every project inside terlar/dev-flake which can be used by flake-parts partitions functionality to get it outside of the main flake.
Thereās no beta, and itās already done, so why hand-wring?
Besides, itās actually itās a good thing it was done a while before the release, to avoid more headaches during ZHF or otherwise disrupting the release process overall.
To some degree, even individual expression reformats would impact backports, e.g. in cases where some breaking updates werenāt backported but a future fix could be backported, the fix diff wouldnāt apply cleanly. In those cases manual resolution would still be necessary. IMO this just rips off the bandaid, and based on NixOS 25.05 ā Release schedule Ā· Issue #390768 Ā· NixOS/nixpkgs Ā· GitHub the last day to do breaking changes (in the general case) would beā¦today. They just did it a week prior.
For backporting, itās actually better to do it just before a release (so before ZHF). If we did it just after release, 25.05 and 24.11 will not be formatted the same way. Weāll have less conflicts the way it was done.