Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions nixos/modules/installer/tools/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ let
nixos-rebuild-ng = pkgs.nixos-rebuild-ng.override {
nix = config.nix.package;
withNgSuffix = false;
withNom = config.system.rebuild.enableNom;
withReexec = true;
};

Expand Down Expand Up @@ -287,6 +288,14 @@ in
'';
};

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.

description = ''
Whether to use ‘nix-output-monitor’ in place of ‘nix’ when rebuilding.
This produces a more aesthetically pleasing terminal experience.
'';
};

imports =
let
mkToolModule =
Expand Down
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ in
nixos-rebuild-specialisations-ng = runTestOn [ "x86_64-linux" ] {
imports = [ ./nixos-rebuild-specialisations.nix ];
_module.args.withNg = true;
_module.args.withNom = true;
};
nixos-rebuild-target-host = runTest {
imports = [ ./nixos-rebuild-target-host.nix ];
Expand Down
18 changes: 18 additions & 0 deletions pkgs/by-name/ni/nix-output-monitor/package.nix
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.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
haskellPackages,
installShellFiles,
lib,
nix,
replaceVars,

# Allow pinning a specific Nix version.
withPinnedNix ? false,
}:
let
inherit (haskell.lib.compose) justStaticExecutables overrideCabal;

# If we're pinning Nix, then substitute with a Nix path; otherwise, just the name of the binary.
ambientOrPinned = name: if withPinnedNix then lib.getExe' nix name else name;

pinnedNixPatch = replaceVars ./pin-a-specific-nix.patch {
nix = ambientOrPinned "nix";
nix-build = ambientOrPinned "nix-build";
nix-shell = ambientOrPinned "nix-shell";
};

overrides = {
passthru.updateScript = ./update.sh;

Expand All @@ -15,13 +29,17 @@ let
testTargets = [ "unit-tests" ];

buildTools = [ installShellFiles ];

patches = [ pinnedNixPatch ];

postInstall = ''
ln -s nom "$out/bin/nom-build"
ln -s nom "$out/bin/nom-shell"
chmod a+x $out/bin/nom-build
installShellCompletion completions/*
'';
};

raw-pkg = haskellPackages.callPackage ./generated-package.nix { };
in
lib.pipe raw-pkg [
Expand Down
62 changes: 62 additions & 0 deletions pkgs/by-name/ni/nix-output-monitor/pin-a-specific-nix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Philip Taron <philip.taron@gmail.com>
Date: Thu, 23 Oct 2025 10:32:59 -0700
Subject: [PATCH] exe: allow pinning a specific Nix version

---
exe/Main.hs | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/exe/Main.hs b/exe/Main.hs
index 5e0f010..01b9e06 100644
--- a/exe/Main.hs
+++ b/exe/Main.hs
@@ -72,18 +72,18 @@ runApp :: String -> [String] -> IO Void
runApp = \cases
_ ["--version"] -> do
hPutStrLn stderr ("nix-output-monitor " <> fromString (showVersion version))
- exitWith =<< runProcess (proc "nix" ["--version"])
- "nom-build" args -> exitWith =<< runMonitoredCommand defaultConfig (proc "nix-build" (withJSON args))
+ exitWith =<< runProcess (proc "@nix@" ["--version"])
+ "nom-build" args -> exitWith =<< runMonitoredCommand defaultConfig (proc "@nix-build@" (withJSON args))
"nom-shell" args -> do
- exitOnFailure =<< runMonitoredCommand defaultConfig{silent = True} (proc "nix-shell" (withJSON args <> ["--run", "exit"]))
- exitWith =<< runProcess (proc "nix-shell" args)
- "nom" ("build" : args) -> exitWith =<< runMonitoredCommand defaultConfig (proc "nix" ("build" : withJSON args))
+ exitOnFailure =<< runMonitoredCommand defaultConfig{silent = True} (proc "@nix-shell@" (withJSON args <> ["--run", "exit"]))
+ exitWith =<< runProcess (proc "@nix-shell@" args)
+ "nom" ("build" : args) -> exitWith =<< runMonitoredCommand defaultConfig (proc "@nix@" ("build" : withJSON args))
"nom" ("shell" : args) -> do
- exitOnFailure =<< runMonitoredCommand defaultConfig{silent = True} (proc "nix" ("shell" : withJSON (replaceCommandWithExit args)))
- exitWith =<< runProcess (proc "nix" ("shell" : args))
+ exitOnFailure =<< runMonitoredCommand defaultConfig{silent = True} (proc "@nix@" ("shell" : withJSON (replaceCommandWithExit args)))
+ exitWith =<< runProcess (proc "@nix@" ("shell" : args))
"nom" ("develop" : args) -> do
- exitOnFailure =<< runMonitoredCommand defaultConfig{silent = True} (proc "nix" ("develop" : withJSON (replaceCommandWithExit args)))
- exitWith =<< runProcess (proc "nix" ("develop" : args))
+ exitOnFailure =<< runMonitoredCommand defaultConfig{silent = True} (proc "@nix@" ("develop" : withJSON (replaceCommandWithExit args)))
+ exitWith =<< runProcess (proc "@nix@" ("develop" : args))
"nom" [] -> do
finalState <- monitorHandle @OldStyleInput defaultConfig{piping = True} stdin
if CMap.size finalState.fullSummary.failedBuilds + length finalState.nixErrors == 0
@@ -108,7 +108,7 @@ printNixCompletion = \cases
exitSuccess
"nom" args@(sub_cmd : _)
| sub_cmd `elem` knownSubCommands ->
- exitWith =<< Process.runProcess (Process.proc "nix" args)
+ exitWith =<< Process.runProcess (Process.proc "@nix@" args)
prog args -> do
putTextLn $ "No completion support for " <> unwords (toText <$> prog : args)
exitFailure
@@ -170,7 +170,7 @@ monitorHandle config input_handle = withParser @a \streamParser -> do
Terminal.hHideCursor outputHandle
hSetBuffering stdout (BlockBuffering (Just 1_000_000))

- current_system <- Exception.handle ((Nothing <$) . printIOException) $ Just . decodeUtf8 <$> Process.readProcessStdout_ (Process.proc "nix" ["eval", "--extra-experimental-features", "nix-command", "--impure", "--raw", "--expr", "builtins.currentSystem"])
+ current_system <- Exception.handle ((Nothing <$) . printIOException) $ Just . decodeUtf8 <$> Process.readProcessStdout_ (Process.proc "@nix@" ["eval", "--extra-experimental-features", "nix-command", "--impure", "--raw", "--expr", "builtins.currentSystem"])
first_state <- initalStateFromBuildPlatform current_system
-- We enforce here, that the state type is completely strict so that we don‘t accumulate thunks while running the program.
let first_process_state = MkProcessState (StrictType.Strict $ firstState @a first_state) (stateToText config first_state)
--
2.51.0

62 changes: 62 additions & 0 deletions pkgs/by-name/ni/nixos-rebuild-ng/0001-replacements.patch
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Philip Taron <philip.taron@gmail.com>
Date: Wed, 22 Oct 2025 17:02:15 -0700
Subject: [PATCH] nixos-rebuild-ng: patch out actual replacements

Produced with `git format-patch -1 --zero-commit --stdout --relative=pkgs/by-name/ni/nixos-rebuild-ng/src HEAD^1`
---
nixos_rebuild/constants.py | 18 +++++++++---------
pyproject.toml | 6 +++---
2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/nixos_rebuild/constants.py b/nixos_rebuild/constants.py
index f79922ea5c87..ee4fc0c49373 100644
--- a/nixos_rebuild/constants.py
+++ b/nixos_rebuild/constants.py
@@ -2,15 +2,15 @@ from typing import Final

# The name of this executable, for purposes of replacing `nixos-rebuild`.
# The derivation replaces this using a patch file.
-EXECUTABLE: Final[str] = "nixos-rebuild-ng"
+EXECUTABLE: Final[str] = "@executable@"

# These names are replaced with absolute paths to Nix in the store in the derivation.
# Some of these names could be either `nix` or `nom`, and are called out as such.
-NIX: Final[str] = "nix"
-NIX_OR_NOM: Final[str] = "nix"
-NIX_BUILD: Final[str] = "nix-build"
-NIX_CHANNEL: Final[str] = "nix-channel"
-NIX_COPY_CLOSURE: Final[str] = "nix-copy-closure"
-NIX_ENV: Final[str] = "nix-env"
-NIX_INSTANTIATE: Final[str] = "nix-instantiate"
-NIX_STORE: Final[str] = "nix-store"
+NIX: Final[str] = "@nix@"
+NIX_OR_NOM: Final[str] = "@nix-or-nom@"
+NIX_BUILD: Final[str] = "@nix-build@"
+NIX_CHANNEL: Final[str] = "@nix-channel@"
+NIX_COPY_CLOSURE: Final[str] = "@nix-copy-closure@"
+NIX_ENV: Final[str] = "@nix-env@"
+NIX_INSTANTIATE: Final[str] = "@nix-instantiate@"
+NIX_STORE: Final[str] = "@nix-store@"
diff --git a/pyproject.toml b/pyproject.toml
index 757067db9f06..68dfa825a824 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,11 +3,11 @@ requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
-name = "nixos-rebuild"
-version = "0.0.0"
+name = "@executable@"
+version = "@version@"

[project.scripts]
-nixos-rebuild = "nixos_rebuild:main"
+@executable@ = "nixos_rebuild:main"

[tool.setuptools.package-data]
nixos_rebuild = ["*.nix.template"]
--
2.51.0

30 changes: 30 additions & 0 deletions pkgs/by-name/ni/nixos-rebuild-ng/0002-help-runs-man.patch
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Philip Taron <philip.taron@gmail.com>
Date: Thu, 23 Oct 2025 05:46:07 -0700
Subject: [PATCH] nixos-rebuild-ng: patch out print_help to use the man page

Produced with `git format-patch -1 --zero-commit --stdout --relative=pkgs/by-name/ni/nixos-rebuild-ng/src`
---
nixos_rebuild/help.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/nixos_rebuild/help.py b/nixos_rebuild/help.py
index 7437550a37b8..dcb730e09ced 100644
--- a/nixos_rebuild/help.py
+++ b/nixos_rebuild/help.py
@@ -1,7 +1,10 @@
import argparse
+from subprocess import run
from typing import NoReturn

+from .constants import EXECUTABLE
+

def print_help(parser: argparse.ArgumentParser) -> NoReturn:
- parser.print_help()
- parser.exit()
+ r = run(["man", "8", EXECUTABLE], check=False)
+ parser.exit(r.returncode)
--
2.51.0

Loading
Loading