An Emacs major mode for editing Nix expressions, powered by the built-in tree-sitter support in Emacs 29+ and the community-maintained Nix tree-sitter grammar.
Features:
- Syntax highlighting for all Nix language constructs
- Semantic distinctions (variables vs properties, function calls vs definitions)
- 100% tree-sitter-nix grammar coverage
- Comprehensive tests
Requirements: Emacs 29+ with tree-sitter support, 30.x includes more improvements.
nix-ts-mode provides comprehensive syntax highlighting and indentation for Nix files.
After installing, enable the mode for Nix files like so:
(require 'nix-ts-mode)
(add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-ts-mode))Or with use-package:
(use-package nix-ts-mode
:mode "\\.nix\\'")For the best syntax highlighting experience with the widest selection of font-lock faces, set the font-lock level to 4 (maximum):
;; Add to your init.el before loading nix-ts-mode
(setq treesit-font-lock-level 4)This enables:
- Fine-grained semantic distinctions (variables vs properties)
- Function parameter highlighting
- Punctuation and bracket highlighting
- Complete visual clarity
- below is a list of what is included at each level
test/highlighting-example.nixcan be use to see the effects of the levels.
- comment
- builtin
- constant
- string
- path
- uri
- number
- operator
- definition
- function-call
- keyword
- parameter
- property
- variable
- bracket
- delimiter
- ellipses
- punctuation
- **paren-base** (override)
- **parameter-atpattern** (override)
- error