From 02d1b2191629a585d23d9933482a3b52af5aa2d7 Mon Sep 17 00:00:00 2001 From: Elec3137 Date: Tue, 10 Feb 2026 10:01:13 -0800 Subject: [PATCH] add nixos-rebuild-diff to show diffs after rebuild --- cli/shell.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cli/shell.nix b/cli/shell.nix index abe2c57..03add7f 100644 --- a/cli/shell.nix +++ b/cli/shell.nix @@ -12,6 +12,23 @@ let # use a more verbose output style for nix than default # only lix supports log-format = multiline-with-logs logFormat = if config.nixowos.system.lix.enable then "multiline-with-logs" else "bar-with-logs"; + + nixos-rebuild-diff = pkgs.writeShellApplication { + name = "nixos-rebuild-diff"; + + runtimeInputs = [ config.nix.package ]; + + text = '' + if [[ $* =~ build|boot|test|switch ]]; then + priorSystem=$(readlink /run/current-system) + newSystem=$(command nixos-rebuild --ask-sudo-password --log-format ${logFormat} "$@" | tail -n 1) + + nix store diff-closures "$priorSystem" "$newSystem" + else + command nixos-rebuild --ask-sudo-password --log-format ${logFormat} "$@" + fi + ''; + }; in { options.nixowos.cli.${name} = { @@ -30,7 +47,7 @@ in # make nix-shell preserve the user's $SHELL nix-shell = /* sh */ ''nix-shell --command "export SHELL=$SHELL; $SHELL"''; - nixos-rebuild = /* sh */ "nixos-rebuild --ask-sudo-password --log-format ${logFormat}"; + nixos-rebuild = /* sh */ "${nixos-rebuild-diff}/bin/nixos-rebuild-diff"; nix = /* sh */ "nix --log-format ${logFormat}"; };