An Opinionated Formatter for Nix

Hi folks! Today we are happy to announce an alpha release of nixfmt, our formatter for Nix code. The work is still in progress, but we can't help sharing what we've done by now, as we consider the project truly important for the community and us as the Nix users. It is released under the MPL 2.0, and contributions are welcome.

At Serokell, we write quite a bit of Nix code, and the lack of tooling surrounding the language has always bothered us. No good formatter existed, and even editor indentation plugins were often lacking. So we set out to change that by ourselves.

We started writing nixfmt, a tool for formatting Nix code in a consistent way. In the project, we're using popular libraries like megaparsec and text, and we use a custom pretty printer originally based on the prettyprinter library.

Currently, nixfmt parses and formats all of nixpkgs in about 20 seconds on a dual-core CPU and individual files like all-packages.nix in less than a second. The project is available at To give it a try, clone it and run nix-build. Then run ./result/bin/nixfmt -w80 some.nix files.nix. For more details, see the .

The tool is not entirely done yet, but the formatting it applies is very consistent and improves overall readability although unattractive in many places. We’re working hard to make it produce good results by the end of the month. In the first place, we aim to reach a nixfmt that generates somewhat pretty code for almost everything. At that point, it will be considered widely usable. Then we’d like to work along with the NixOS community people to bring the project up to standard for an officially accepted code formatter.

If you want to see how it works, we deployed it at We kindly invite you to help with the final stretch. Feel free to contribute!

Serokell is a software development company focused on building innovative solutions for complex problems. Come visit us at!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store