# The Uncompromising Nix Code Formatter

**URL:** https://discourse.nixos.org/t/the-uncompromising-nix-code-formatter/17385
**Category:** Links
**Created:** [January 28, 2022, 2:37pm UTC](https://discourse.nixos.org/t/the-uncompromising-nix-code-formatter/17385 "2022-01-28T14:37:29Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![kamadorueda](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kamadorueda/32/3834_2.png) [@kamadorueda](https://discourse.nixos.org/u/kamadorueda)
#### Post date: [February 2, 2022, 1:57am UTC](https://discourse.nixos.org/t/the-uncompromising-nix-code-formatter/17385/3 "2022-02-02T01:57:47Z")

</div>

I designed Alejandra because I wanted a formatter to tell me how every piece of my code should look like, no exceptions

Speed, getting semantics perfectly correct, etc,  
that is just what a good formatter should have,  
this is not negotiable

This community is getting big  
and we still do not have something like that.  
Other communities like Rust, Go, Terraform, Python, they do have one.

There is clearly a problem to solve

Now, here are some technical facts though,  
(I don’t care about beauty/style arguments)  
to answer your question:

1. Nixpkgs-fmt has bugs: [Issues · nix-community/nixpkgs-fmt · GitHub](https://github.com/nix-community/nixpkgs-fmt/issues)

2. Nixfmt has bugs: [Escape Characters · Issue #81 · serokell/nixfmt · GitHub](https://github.com/serokell/nixfmt/issues/81)

3. Alejandra was able to address certain bugs which I found in other formatters

See why:

1. Format nixpkgs with nixfmt, run nixpkgs-review,  
and you’ll discover that many packages on Nixpkgs no longer build

2. Format Nixpkgs with nixpkgs-fmt, run nixpkgs-review,  
and you’ll discover that 37210 (almost all) packages on Nixpkgs needs  
rebuilding

Do you want a formatter breaking your builds?  
I’m sure you don’t

Bugs multiplied by the 2.3 millions lines of Nix code that Nixpkgs have,  
adds up a lot

Now, format Nixpkgs with Alejandra, you’ll get only 89 rebuilds!!!  
all of them justified. No bugs.

Other facts:

1. Nixpkgs-fmt is not extensive:

2. Last release of nixfmt: Feb 10, 2020 (2 years ago)

3. Where are the tests of nixfmt? [Add a test suite · Issue #13 · serokell/nixfmt · GitHub](https://github.com/serokell/nixfmt/issues/13)

4. It’s been more than ten minutes on a 16 cores machine,  
and nixfmt is still formatting Nixpkgs

In short, the important differences:

- Correctness (bugs, broken builds)
- Totality (a formatter must format everything)
- Speed (dev time is expensive)

Style is subjective and I’ve been working lately on getting Alejandra into a format that is similar to Nixpkgs, in other words “beautiful” to the 51%: [Issues · kamadorueda/alejandra · GitHub](https://github.com/kamadorueda/alejandra/issues?q=is%3Aissue+is%3Aclosed)

---

_[View the full topic](https://discourse.nixos.org/t/the-uncompromising-nix-code-formatter/17385)._
