-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
nixos-rebuild-ng: support using nix-output-monitor #455383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging-nixos
Are you sure you want to change the base?
Changes from all commits
a6ede7f
7154574
2f3f59b
effe701
25492df
c39ea91
525891d
079cf93
e9be87f
d0e571d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't really review the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
| @@ -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 | ||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll return to the constants/ |
| 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 | ||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.