nix-mode
nix-mode copied to clipboard
Support for alejandra and nixpkgs-format
Hi, I've been meaning to switch to alejandra for formatting, and the only real blocker for me at this point is a convenient function in emacs to format my current buffer. nixpkgs-format also exists as a potential future replacement for nixfmt, though I've heard development interest in it has petered out a bit.
Either way, is there a chance these alternatives could be supported? I think their interfaces from an application point of view are similar enough that they are basically drop-in replacements for one another, so maybe a little configuration switch to choose one of them (that can be overridden with per-buffer or dir-locals when necessary) is simple enough?
I'm happy drafting that up myself, just want to test the waters before I spring it on here and see if it will be considered too much feature creep to do this for every nix formatter that may come into existence ;)
I'm using reformatter.el which is convenient: (reformatter-define nix-alejandra :program "alejandra")
and then either (add-hook 'nix-mode-hook 'nix-alejandra-on-save-mode)
or simply M-x nix-alejandra
. Perhaps nix-format.el
could use reformatter.
Hm, that does indeed cover everything I'd like to do. It's even already in my config through elm-mode, so I guess I might just switch to that for now. I'd be very in favor of switching to reformat.el
as a backend, it's cool that there is a small standardization effort here, but that's a bit off-topic - separate issue?
I'd still like to see support for more that nix-fmt
, though. nixpkgs-fmt
and alejandra
are big improvements over nix-fmt
, so it would be nice to expose new users to them through this package. I don't think we'll see too many new ones created either.
On the other hand, I realize it'd feel a bit unclean to have multiple formatting functions lying around - especially because it'll be hard to remove formatters that don't see much maintenance in the future. It might also be confusingly hard to tell which to use. The maintenance burden would be low here, though, especially if it's backed by reformat.el
.
We could also wait for the RFC that is choosing one of them as the default for nixpkgs to resolve, and switch to whichever wins?
The "official" Alejandra integration suggests https://github.com/lassik/emacs-format-all-the-code, which also supports nixpkgs-format
.