In What are your goals for 19.09? I said that my plan was to have a release of
nix-fmt 1.0 for the next release. We are getting there!
The project has since been renamed
nixpkgs-fmt due to naming collisions. More importantly, nixpkgs-fmt is usable today!
I encourage you all to try it out, use it and report formatting issues back to the project so that we can make the best nix code formatter out there.
- online: https://nix-community.github.io/nixpkgs-fmt/
- nixpkgs unstable:
nix-env -iA nixpkgs-fmt
nix-env -f https://github.com/nix-community/nixpkgs-fmt/archive/master.tar.gz -i
- pre-commit hook: see https://github.com/nix-community/nixpkgs-fmt#pre-commit-hook
Why another code formatter?
If you are confused why we need another nix code formatter, first, it’s very understandable
The TL;DR is that nixpkgs-fmt is taking a different approach than existing formatters and is specialized to format the nix code in nixpkgs, favourizing mergeability. But it’s great to format any nix code obviously. For a longer read see: https://github.com/nix-community/nixpkgs-fmt#design-decisions
How to contribute
The easiest is to go to the online formatter and submit code samples when you see something not formatted right. Or if you like to write Rust code your contribution is also welcome.
The goal right now is to have as many people as possible test it an be exposed to the format. The hope is to reach consensus and have a majority of happy users. nixpkgs-fmt’s output is quite close to the format used in nixpkgs so hopefully it won’t be too controversial. Reach 1.0 before 19.09.
After the 19.09 release I am hoping to add hooks to nixpkgs to start formatting the code. We need to discuss how to do that but I think this can be quite gradual.
Another thing I would like to explore is how to create rules that can be language-agnostic by emitting and parsing back a JSON representation of the AST tree. This would make it easy for example to rewrite all the URLs to strings with a simple python/ruby/bash script.
Thanks a lot to @matklad who implemented most of nixpkgs-fmt. He also invented the rowan lossless parsing library upon which this project is based.
Thanks also to @jD91mZM2 who wrote the rnix library and was responsive to our pull-requests.