tty.is_

Making rebuilds in NixOS a bit nicer

If you've been around the block with NixOS, you'll likely have spent a bit of time deciphering nixos-rebuild output.

sudo nixos-rebuild --flake .#hostname

… and now, this:

nixos-rebuild.png
Figure 1: What are we even looking at?

For reference, the X/YYY/ZZZ built bit shows you

The same goes for the copied section.

You can add a -v flag to your args to get it to spit out more info, but it can be kind of a lot, and it can be pretty difficult to tell "what's taking so long" unless it happens to be compiling emacs from scratch again.

nh knows what's up

Enter nh – a tool that wraps nixos-rebuild and a few other NixOS platform tools to produce a more human-consumable UX. It's both easy to use and easy to understand.

Building

nh performs sudo on your behalf, so you don't have to. oh, it's also smart enough to find the right hostname to build if you're running a flake-based setup, so no more .#whatever-hostname-this-is – just . will do. Here's what I do on my machine to install updated bits:

cd my-flake-dir
nix flake update
nh os switch .

and here's the output I'm greeted with:

nh-build.png
Figure 2: build in progress…

Quite a bit easier to grok - you can see what's downloading and from where. When things are building, that's also super clear. When the build is done, you also get a great change summary:

nh-build-done.png
Figure 3: build finished

Another awesome thing about using nh to build/switch – you can pass --dry to show the actions without running them.

Passing --ask causes nh to pause after it has printed the diff of your build to give you a chance to apply the changes or back out, which is pretty cool too.

Search

nh provides lightweight package search via nh search:

nh search emacs
nh-search.png
Figure 4: searching for emacs

Clean

nh also provides a clean command that can look at the user's profiles, other user's profiles (permissions required, of course), and/or the system's profile. It can be a one stop shop for cleaning up old cruft and consistently removes things I would otherwise forget.

nh-clean.png
Figure 5: cleaning everything

How to acquire

nh is of course already in nixpkgs, and if you've read my post on comma, you probably already know the easiest way to try this out:

, nh --help

Make sure to check out the project's GitHub for more info.