Skip to content

Parse, manipulate, and reconstruct Nix source code with high-level abstractions.

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
GPL-3.0
COPYING
LGPL-3.0
COPYING.LESSER
Notifications You must be signed in to change notification settings

hoh/nix-manipulator

Nix-manipulator (Nima)

A Python library and tools for parsing, manipulating, and reconstructing Nix source code.

Overview

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.

Features and Goals

  • 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.

Non-goals

  • Preserving eccentric formatting that does not respect RFC-166 and would add unnecessary complexity.

Targeted applications

  • Updating values in Nix code by hand, scripts, pipelines, and frameworks.
  • Writing refactoring tools.
  • Interactive modifications from a REPL.

Foundations

Nix-manipulator leverages tree-sitter , a multilingual concrete-syntax AST, and its Nix grammar tree-sitter-nix.

Project Status

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

Target Audience

Intermediate Nix users and developers working with Nix code manipulation.

CLI Usage

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 true

Remove an attribute

nima rm -f package.nix doCheck

Test/validate that a Nix file can be parsed

nima test -f package.nix

About

Parse, manipulate, and reconstruct Nix source code with high-level abstractions.

Topics

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
GPL-3.0
COPYING
LGPL-3.0
COPYING.LESSER

Stars

Watchers

Forks

Packages

No packages published