This Emacs library provides commands and a minor mode for easily reformatting Nix source code using the nixfmt command.
If you choose not to use one of the convenient
packages in MELPA, you'll need to
add the directory containing nixfmt.el to your load-path, and
then (require 'nixfmt).
Customise the nixfmt-command variable as desired, then call
nixfmt-buffer or nixfmt-region as convenient.
Enable nixfmt-on-save-mode in Nix buffers like this:
(add-hook 'nix-mode-hook 'nixfmt-on-save-mode)or locally to your project with a form in your .dir-locals.el like this:
((nix-mode
(mode . nixfmt-on-save)))You might like to bind nixfmt or nixfmt-buffer to a key,
e.g. with:
(define-key 'nix-mode-map (kbd "C-c C-f") 'nixfmt)