A Python library and tools for parsing, manipulating, and reconstructing Nix source code.
Started during SaltSprint 2025, Nix-manipulator aims to fill the absence of tools for easily updating and editing Nix code. Popular tools such as nix-update rely on simple string replacement or regular expressions for updating Nix code.
- Ease of use - Simple CLI and API for common operations.
- High-level abstractions make manipulating expressions easy.
- Preserving formatting and comments in code that respects RFC-166.
- Preserving eccentric formatting that does not respect RFC-166 and would add unnecessary complexity.
- Updating values in Nix code by hand, scripts, pipelines, and frameworks.
- Writing refactoring tools.
- Interactive modifications from a REPL.
Nix-manipulator leverages tree-sitter , a multilingual concrete-syntax AST, and its Nix grammar tree-sitter-nix.
The project is still in early-stage:
- Not all Nix syntax is supported yet
- Test-driven approach prevents regressions
- CLI and API are still evolving and subject to change
- 28991 / 39573 (73.26%) Nix files from nixpkgs could be parsed and reproduced
Intermediate Nix users and developers working with Nix code manipulation.
Nix-manipulator provides a command-line interface for common operations:
Set a value in a Nix file
nima set -f package.nix version '"1.2.3"'Set a boolean value
nima set -f package.nix doCheck trueRemove an attribute
nima rm -f package.nix doCheckTest/validate that a Nix file can be parsed
nima test -f package.nix