Home

Awesome

Melpa Status Melpa Stable Status Build Status <a href="https://www.patreon.com/sanityinc"><img alt="Support me" src="https://img.shields.io/badge/Support%20Me-%F0%9F%92%97-ff69b4.svg"></a>

nixpkgs-fmt.el

This Emacs library provides commands and a minor mode for easily reformatting Nix source code using the nixpkgs-fmt command.

Installation

If you choose not to use one of the convenient packages in MELPA, you'll need to add the directory containing nixpkgs-fmt.el to your load-path, and then (require 'nixpkgs-fmt).

Usage

Customise the nixpkgs-fmt-command variable as desired, then call nixpkgs-fmt-buffer or nixpkgs-fmt-region as convenient.

Enable nixpkgs-fmt-on-save-mode in Nix buffers like this:

(add-hook 'nix-mode-hook 'nixpkgs-fmt-on-save-mode)

or locally to your project with a form in your .dir-locals.el like this:

((nix-mode
   (mode . nixpkgs-fmt-on-save)))

You might like to bind nixpkgs-fmt or nixpkgs-fmt-buffer to a key, e.g. with:

(define-key 'nix-mode-map (kbd "C-c C-f") 'nixpkgs-fmt)
<hr>

💝 Support this project and my other Open Source work

💼 LinkedIn profile

✍ sanityinc.com

🐦 @sanityinc