An Emacs major mode for editing Nix expressions. There is also a manual available at nix-mode.org.
A quick list of what is provided.
This is the main usage of nix-mode. This provides basic handling of .nix files. Syntax highlighting and indentation support using SMIE are provided. nix-mode can be used with the following snippet:
(require 'nix-mode) (add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))
or with use-package:
(use-package nix-mode :mode "\\.nix\\'")
nix.el contains some miscellaneous tools for Nix developers. Interactive functions include:
nix-unpack - unpack source of a Nix attribute.
To use this just type:
Followed by your Nix path & attribute path.
nix-build - build a Nix derivation.
This is meant to work similarly to M-x compile. It will use your current directory & build it if there is a default.nix there.
nix.el also provides some basic functions for interfacing with Nix. Some variables are provided to point to the Nix binaries that can be used in Lisp code:
Other useful functions for Lisp scripts are provided:
- nix-system - Get the current system, detected by Nix
nix-repl.el has two purposes.
First, it provides an interface for completion, used by nix-company.el.
Second, it provides an interactive function to open an repl. You can open this with:
When nix-prettify-mode is enabled, hash-parts of the Nix store file names are
prettified, i.e. displayed as
nix-prettify-char character (
… by default.).
This is based on a similar mode for Guix: Prettify Mode (Emacs-Guix Reference Manual).
Other Emacs packages
@shlevy has an excellent package for integrating nix-shell into emacs. It is available at shlevy/nix-buffer.
@travisbhartwell also has some package dealing with Nix. They are available at travisbhartwell/nix-emacs.