nixos-rebuild-ng: add --diff argument

This displays the package updates, additions, and removals to the user.
This commit is contained in:
Elec3137
2026-02-10 18:03:24 -08:00
parent 39d1a3a7cb
commit 30cb9399cc
4 changed files with 42 additions and 0 deletions
@@ -308,6 +308,14 @@ It must be one of the following:
option, it is possible to build non-flake NixOS configurations even if
the current NixOS systems uses flakes.
*--diff*
show the diff between the system closure in /run/current-system
and the newly built system closure.
(avaliable for actions: build, boot, test, switch)
This is similar to running:
"nix store diff-closures /run/current-system result" after build
In addition, *nixos-rebuild* accepts following options from nix commands that
the tool calls:
@@ -197,6 +197,12 @@ def get_parser() -> tuple[argparse.ArgumentParser, dict[str, argparse.ArgumentPa
help="Selects an image variant to build from the "
"config.system.build.images attribute of the given configuration",
)
main_parser.add_argument(
"--diff",
action="store_true",
help="prints out the diff between the current system "
"and the newly built one using nix store diff-closures"
)
main_parser.add_argument("action", choices=Action.values(), nargs="?")
return main_parser, sub_parsers
@@ -259,6 +265,14 @@ def parse_args(
if args.no_build_nix:
parser_warn("--no-build-nix is deprecated, we do not build nix anymore")
if args.diff and args.action not in (
Action.SWITCH.value,
Action.BOOT.value,
Action.BUILD.value,
Action.TEST.value
):
parser_warn(f"--diff is a no-op with '{args.action}'")
if args.action == Action.EDIT.value and (args.file or args.attr):
parser.error("--file and --attr are not supported with 'edit'")
@@ -537,6 +537,18 @@ def list_generations(profile: Profile) -> list[GenerationJson]:
reverse=True,
)
def diff_closures(path_to_config: Path):
run_wrapper(
[
"nix",
*FLAKE_FLAGS,
"store",
"diff-closures",
"/run/current-system",
path_to_config
]
)
def repl(build_attr: BuildAttr, nix_flags: Args | None = None) -> None:
run_args = ["nix", "repl", "--file", build_attr.path]
@@ -321,6 +321,14 @@ def build_and_activate_system(
grouped_nix_args=grouped_nix_args,
)
if args.diff and args.action in (
Action.SWITCH.value,
Action.BOOT.value,
Action.BUILD.value,
Action.TEST.value
):
nix.diff_closures(path_to_config)
_activate_system(
path_to_config=path_to_config,
action=action,