Nix formatting team: Full Nixpkgs reformat

After the previous partial Nixpkgs reformat, the Nix formatting team is now ready for follow-up: To fully standardise formatting in Nixpkgs! :rocket:

Highlights:

  • 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 :tada: at 2025-04-01T19: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:

maintainers/scripts/auto-rebase/run.sh master

Method 2: git mergetool

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.

See the package description for how to use it!

Personal refocusing

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!

55 Likes