with apologies

NixOS channels

Richard Mortier · December 13, 2023 · #old #linux #nixos

I don’t pretend to understand NixOS configuration fully yet, what with Flakes and channels and so forth. But I did find the following usful to setup channels consistently so that I could have a single config that used both.

sudo nix-channel --list # to list known channels
sudo nix-channel --remove nixos # to remove a channel
sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos # to go bleeding edge

…ultimately resulting in:

$ nix-channel --list # channels are stored per-user, and $(whoami) != root
$ sudo nix-channel --list
nixos https://nixos.org/channels/nixos-unstable
nixpkgs https://nixos.org/channels/nixos-unstable

Upgrading to the latest release is then something like:

pushd ~/rc-files/nixos/
sudo nix-channel --update
nix flake update
sudo nixos-rebuild switch --upgrade-all
popd

…and finally, garbage collecting old versions once you’re satisfied the new one works:

sudo nix-collect-garbage -d
nix-collect-garbage -d
sudo nix-store --gc
nix-store --gc 

And yes, some of the incantations above might be a little cargo-cultish and not strictly necessary. But at various points they’ve seemed necessary to me, and now they’re in my shell history, they’re what I got.