How to make nixos-rebuild output more informative?

Is there a way or program to make the output of nixos-rebuild more informative? I know that there are wrappers for apt and was wondering, if there is some equivalent for nixos-rebuild.

For example, i find this output not very informative:

these 103 paths will be fetched (423.69 MiB download, 1619.10 MiB unpacked):

I would rather like to see the individual package size, old version → new version, the packages grouped together according to their dependency on each other, coloring etc. if possible. Is there a way to do that?

old version → new version

For a nix-build in isolation, this does not make a lot of sense: there can be multiple versions of a package in the store, and in your current system. nix-build does not necessarily know whether you’re “upgrading” to a newer version, or adding one besides the existing one.

That said, there are tools like nvd or nix store diff-closures that allow you to compare two derivations.

For your other points, they do seem like reasonable requests. nix-output-monitor for one seems to have a dependency tree view.

1 Like

It works, thank you! It’s very interesting to see more of what nix is doing. :slightly_smiling_face:

For reference, i installed nix-output-monitor and am now running sudo nixos-rebuild switch --upgrade &| nom (i’m using fish).

For listing changes after upgrading, I find this useful:

1 Like

I stole this from a colleague: nixos-config/update-diff.nix at 09d5c694db53d4ddfeefdc81e551a496f0cdf455 · R-VdP/nixos-config · GitHub

It gives me a nice overview of what changed between the old generation and the new.

(You need to have the nix-command experimental feature enabled in order to use the new nix CLI.)

1 Like

This doesn’t work for me, do you know why?

~ ❯ nvd diff $(ls -d1v /nix/var/nix/profiles/system-*-link|tail -n 2)                                                                
Path does not exist: v0.10.1 [+git]

If i run

~ ❯ sudo unbuffer nixos-rebuild switch --upgrade &| nom && nvd diff /run/current-system result                                        7s
unpacking channels...
building Nix...
building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for sperber...
setting up tmpfiles
Finished at 17:01:19 after 7s
Path does not exist: result

it also doesn’t work. This doesn’t work either:

~ ❯ nvd diff result-old result-new
Path does not exist: result-old

@R-VdP could you please elaborate on what i have to do to use it in my configuration.nix so that it is run after each nixos-rebuild? I’m still learning Nixos and have never seen this before…

I tried to enable experimental-features like this:

  nix = {
    settings = { auto-optimise-store = true; };
    extraOptions = "experimental-features = true";
    gc = {
      automatic = true;
      dates = "daily";
      options = "--delete-older-than 7d";

But it’s failing… :pensive:

Yeah, it should be something like

nix = {
  settings.experimental-features = [ "nix-command" ];

and then you can put the contents of the module that I shared earlier, in configuration.nix:

system.activationScripts.diff = ''
  if [[ -e /run/current-system ]]; then
    echo "NixOS system closure diff:"
    ${pkgs.nix}/bin/nix store diff-closures /run/current-system "$systemConfig"

Or you copy the module in a separate file next to configuration.nix, and in configuration.nix you say imports = [ ./update-diff.nix ];

Does that makes things clearer?

1 Like

It works, thank you! :slightly_smiling_face:

I found a way to tweak its legibility a bit. It’s not perfect but still an improvement.

TLDR for Noobs like me:

Add choose to your environment.systemPackages.

Add the following to configuration.nix:

nix.settings.experimental-features = [ "nix-command" ];
  system.activationScripts.diff = ''
    if [[ -e /run/current-system ]]; then
      echo -e "\n***            ***          ***           ***           ***\n"
      ${pkgs.nix}/bin/nix store diff-closures /run/current-system "$systemConfig" | grep -w "→" | grep -w "KiB" | column --table --separator " ,:" | ${pkgs.choose}/bin/choose 0:1 -4:-1 | ${pkgs.gawk}/bin/awk '{s=$0; gsub(/\033\[[ -?]*[@-~]/,"",s); print s "\t" $0}' | sort -k5,5gr | ${pkgs.choose}/bin/choose 6:-1 | column --table
      echo -e "\n***            ***          ***           ***           ***\n"

If you want to have further information while building:

Add nix-output-monitor to your environment.systemPackages.

Alias the following commands to upgrade Nixos:

sudo nixos-rebuild switch --upgrade &| nom && fish (in fish)
sudo nixos-rebuild switch --upgrade |& nom && bash (in bash)

nom will blank out the sudo password prompt. It will only appear briefly. You can still enter the pasword and press enter. It will proceed as normal.

Bonus tip: nix-tree is a very useful application to examine your packages, their sizes and their dependencies.

1 Like