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:
For reference, the X/YYY/ZZZ built
bit shows you
- X: how many things are currently building
- YYY: how many things are finished building
- ZZZ: how many things need to be built total
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:
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:
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
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.