Metadata-Version: 2.4
Name: nix-manipulator
Version: 0.1.0
Summary: A Python library for parsing, manipulating, and reconstructing Nix source code with high-level abstractions while preserving formatting and comments in RFC-formatted code.
Project-URL: Homepage, https://codeberg.org/hoh/nix-manipulator
Project-URL: Source, https://codeberg.org/hoh/nix-manipulator
Project-URL: Tracker, https://codeberg.org/hoh/nix-manipulator/issues
Author-email: Hugo Herter <git@hugoherter.com>
License-Expression: LGPL-3.0-or-later
License-File: COPYING
License-File: COPYING.LESSER
License-File: LICENSE
Keywords: ast,code-manipulation,nix,parsing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Requires-Dist: pydantic>=2.11.4
Requires-Dist: pygments>=2.19.1
Requires-Dist: tree-sitter-nix>=0.1.0
Requires-Dist: tree-sitter>=0.24.0
Description-Content-Type: text/markdown

# 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](https://github.com/Mic92/nix-update) rely on 
[simple string replacement](https://github.com/Mic92/nix-update/blob/fbb35af0ed032ab634c7ef9018320d2370ecfeb1/nix_update/update.py#L26)
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](https://tree-sitter.github.io/tree-sitter/)
, a multilingual concrete-syntax AST, and its Nix grammar [tree-sitter-nix](https://github.com/nix-community/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
```shell
nima set -f package.nix version '"1.2.3"'
```

Set a boolean value
```shell
nima set -f package.nix doCheck true
```

Remove an attribute
```shell
nima rm -f package.nix doCheck
```

Test/validate that a Nix file can be parsed
```shell
nima test -f package.nix
```