Skip to content

nixos-rebuild-ng: support using nix-output-monitor#455383

Draft
philiptaron wants to merge 10 commits intoNixOS:staging-nixosfrom
philiptaron:nixos-rebuild-ng-enhancements
Draft

nixos-rebuild-ng: support using nix-output-monitor#455383
philiptaron wants to merge 10 commits intoNixOS:staging-nixosfrom
philiptaron:nixos-rebuild-ng-enhancements

Conversation

@philiptaron
Copy link
Contributor

@philiptaron philiptaron commented Oct 24, 2025

This PR introduces the NixOS option system.rebuild.enableNom, which causes nixos-rebuild-ng to use nix-output-manager to display a beautiful tree of dependencies being built.

Its first commit is from #454982 which should be merged first.

Recommend reviewing commit-by-commit. Most of the commits prior to the last one are just refactoring and could be jettisoned if objected to, but ... I like them. 🙂

I tested this out on my system and it works great.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

I'm interested in using `nom` for `nixos-rebuild`, which wants to do this.
In order to avoid the patch breaking on upgrade without someone noticing, it's applied unilaterally, just with do-nothing replacements.
This enables removal of the `with` statements in the derivation.
It's a little strange to patch something that's in Nixpkgs, but it works great.
This provides the place to customize the Nix being executed without needing to use `propagatedBuildInputs`.
`nom` doesn't accept `--extra-experimental-features` before `nom build`; since `nix` accepts it anywhere in the command line, put it after the build.

The tests also need to be updated for the `NIX_OR_NOM` constant.
This uses `nix-output-monitor` to produce a much better looking `nixos-rebuild` experience.
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Oct 24, 2025
@nix-owners nix-owners bot requested a review from maralorn October 24, 2025 22:29
Copy link
Contributor

@thiagokokada thiagokokada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did just a very high look at this, but there is a bunch of controversial changes:

  • It seems that now this always run the reexec code, while the original version this is conditionally enabled on purpose (we disable this if the user runs nixos-rebuild-ng standalone, i.e., not as part of NixOS, because reexec can do the wrong thing in those cases)
  • There is some undocumented changes in behavior, like printing help instead of the manpage
  • Hardcoding binary names to be patched later. This seems bad because we will need to update the patch every time we need to add a new executable
  • Not sure why we need to split the package in 3 files? I like the split between tests and the main package, but anything else seems unnecessary

In general this PR just seems to be trying to many things at once. To get it to a mergeable state I would recommend trying to focus in either introducing nix-output-monitor or refactoring the code. But even them I would prefer for us to talk before doing bigger refactoring, there is a reason a few things are the way they are.

@philiptaron philiptaron marked this pull request as draft October 24, 2025 22:56
@philiptaron
Copy link
Contributor Author

But even them I would prefer for us to talk before doing bigger refactoring, there is a reason a few things are the way they are.

Yes, let's definitely do that. How about here? I'm also available on Matrix, but for these sorts of discussions I prefer GitHub.

I'll respond in separate threads to the other issues, and I'm always glad to split into multiple PRs.

@thiagokokada
Copy link
Contributor

thiagokokada commented Oct 24, 2025

Yes, let's definitely do that. How about here? I'm also available on Matrix, but for these sorts of discussions I prefer GitHub.

Since I think this will need some back and forth I think Matrix will work better. But as a general feedback:

  • Avoid patching code that is already in nixpkgs tree, this is why the constants.py file is that way and unless there is a better solution I would prefer to keep it as-is
  • I prefer to use the Python wrapper to set the PATH for external programs instead of setting the full path for each program
  • Either implement a new feature or refactor, don't do both in the same PR

I think this should be enough for now, but if you want I can do a proper review tomorrow.

@philiptaron
Copy link
Contributor Author

Is there a matrix room for these sorts of discussions? One reason I favor GitHub is due to the ease with which we can scope the discussion but still have it in public. The other is that my favorite matrix client just got ejected from Nixpkgs due to a dependency on libsoup, so I am currently adapting (poorly) to other clients.

};

options.system.rebuild.enableNom = lib.mkEnableOption "" // {
default = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the default already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll remove.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really review the nix-output-monitor changes so you better ping the maintainer for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But do we really need those patches? When we wrap the Python programs we add everything from nativeBuildInputs to the PATH. So I assume just adding nix-output-monitor to nixos-rebuild-ng derivation should be sufficient here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I preferred to avoid the wrapper in favor of embedding the Nix store path in the file, but I'll respect your choice in the matter.

pytestFlags = [ "-vv" ];

makeWrapperArgs =
lib.optional (!withReexec) "--set NIXOS_REBUILD_REEXEC_ENV 1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this looks a clever way to avoid having this as a build constant, but the reason we had this is because we can run nixos-rebuild-ng without building it (by running nix-shell -A nixos-rebuild-ng.devShell && python -m nixos_rebuild) and this is nice for hacking new features.

Now if you do the same this will try to re-exec instead so you can really hack new things, unless you remember to pass --no-reexec flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am against us patching files for code that is inside the nixpkgs street since this makes adding new features unnecessary complicated: we need to add the code first, commit, modify the code, create a patch and commit the path. This is why the constants.py file was the way it was.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll return to the constants/--replace-fail route.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let's avoid needing to patch code that is inside nixpkgs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll return to the constants route.

Copy link
Contributor

@thiagokokada thiagokokada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, does this support --target-host and --build-host ? I don't think it is necessarily a blocker to not support them, but if we don't support we need to at least document this somewhere.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants