nixos-rebuild-ng: init by thiagokokada · Pull Request #354029 · NixOS/nixpkgs · GitHub.
Hello folks .
I am here to collect earlier feedback about the PR above, a Work-in-Progress rewrite of nixos-rebuild
in Python. The objective is to eventually it become a drop-in replacement, but first I want to know if this is something people thinks it is a good idea before I invest more time in its development.
Below is a copy of the PR description including technical reasons in why I am using Python. By the way, to be clear, if there are people that want this in another language (e.g.: Rust looks another good option) I am all in and could close this PR, but I don’t have enough familiarity in the language to help here.
Opening a PR to collect early feedback before I sink more time in this. Keep in mind that while code reviews are welcome, this is not the focus for this PR yet.
The current state of nixos-rebuild
is dare: it is one of the most critical piece of code we have in NixOS, but it has tons of issues:
- The code is written in Bash, and while this by itself is not necessary bad, it means that it is difficult to do refactorings due to the lack of tooling for the language
- The code itself is a hacky mess. Changing even one line of code can cause issues that affects dozens of people
- Lack of proper testing (we do have some integration tests, but no unit tests and coverage is probably pitiful)
- The code predates some of the improvements
nix
had over the years, e.g.: it builds Flakes inside a temporary directory and read the resulting symlink since the code seems to predate--print-out-paths
flag
Given all of those above, improvements in the nixos-rebuild
are difficult to do. A full rewrite is probably the easier way to improve the situation since this can be done in a separate package that will not broke anyone. So this is an attempt of the rewrite.
The language of choice here is Python. I am open to other options here, and I mostly choose Python since it is the language I am most comfortable here, but I am open for other options. Still, I think Python is a good choice because:
- It is the language of choice for many critical things inside
nixpkgs
, like theNixOSTestVM
andsystemd-boot
activation scripts - It is a language with great tooling, e.g.:
mypy
for type checking,ruff
for linting,pytest
for unit testing - It is a scripting language that fits well with the scope of this project
- Python’s standard library is great and it means we will probably need zero external dependencies for this project. For example,
nixos-rebuild
currently depends injq
for JSON parsing, while Python hasjson
in standard library
I am aware about the current switch-to-configuration-ng
rewrite, however I am not sure what is the scope of that project vs nixos-rebuild
. If the idea is just a drop-in replacement than both of those rewrites are ortogonal, since nixos-rebuild
also includes some extra logic for e.g.: profile management. If the idea is to migrate more and more logic to switch-to-configuration-ng
and eventually drop nixos-rebuild
, I am happy to close this PR.