Event

Event
17:15
-
17:20
Day 1
Nix-manipulator: Python library to manipulate Nix code with ease
Assembly-Event
<p><a href="https://github.com/hoh/nix-manipulator">Nima</a>, the Nix Manipulator, is a new Python library and collection of tools for <strong>parsing, manipulating and reconstructing</strong> Nix source code.</p> <p>This presentation will introduce the project, its original goals, key features, and practical applications. It will explore the tradeoffs and decisions made during development and demonstrate how to use its various features.</p> <h3>Context</h3> <p>Started during <a href="https://saltsprint.org/">SaltSprint</a> 2025, Nima aims to fill the absence of tools for easily updating and editing Nix code. Popular tools such as <a href="https://github.com/Mic92/nix-update">nix-update</a> rely on <a href="https://github.com/Mic92/nix-update/blob/fbb35af0ed032ab634c7ef9018320d2370ecfeb1/nix_update/update.py#L26">simple string replacement</a> or regular expressions for updating Nix code.</p> <h3>Goals</h3> <ul> <li>Ease of use.</li> <li>High-level abstractions make manipulating expressions easy.</li> <li>Preserving formatting and comments in code that respects RFC-166.</li> </ul> <p>Eccentric formatting that does not respect RFC-166 and would add unnecessary complexity may not be preserved.</p> <h3>Targeted applications</h3> <ul> <li>Updating values in Nix code by hand, scripts, pipelines, and frameworks.</li> <li>Writing refactoring tools.</li> <li>Interactive modifications from a REPL.</li> </ul> <h3>Foundations</h3> <p>Nima builds on <strong>tree‑sitter</strong>, a multilingual concrete‑syntax AST, with the <a href="https://github.com/nix-community/tree-sitter-nix">tree‑sitter‑nix</a> grammar providing lossless parsing of Nix files.</p> <h3>Project status</h3> <p>The project is still in <strong>early‑stage</strong>:</p> <ul> <li>Most Nix syntax is supported, but not all everything yet.</li> <li>Test-driven approach prevents regressions.</li> <li>CLI and API stability is still evolving.</li> </ul> <h3>Links</h3> <p>Source: https://github.com/hoh/nix-manipulator Announcement: https://discourse.nixos.org/t/announcing-nix-manipulator-nima-structured-edits-for-nix-that-keep-formatting/68513/11</p>