Installing NixOS on a new drive

So, in the end, this turned out to be slightly nontrivial.

I had to also generate the directory as indicated here and then chown it as my user.

Things worked flawlessly afterward.


Steps:

  1. Install new drive into the system.
  2. Create a GPT partition table, with at least two partitions. A fat32 boot partition (labelled boot-new) and a root partition (labelled root-new) with a filesystem of your choice.
  3. Ensure the boot flag is set on the boot partition (without it, in my experience, nixos-install wasn’t installing the bootloader).
  4. Create a new directory for the installation, say /mnt/new.
  5. Mount partitions:
mount /dev/disk/by-label/root-new /mnt/new && \
mkdir /mnt/new/boot  && \
mount /dev/disk/by-label/boot-new /mnt/new/boot
  1. mkdir /mnt/new/etc && cp -r /etc/nixos /mnt/new/etc/
  2. cd /mnt/new
  3. nixos-generate-config and adjust values in filesystems
  4. nixos-install --root /mnt/new

This should install NixOS on the new drive. Once done, reboot and select the new drive from the boot order in BIOS.

Once booted as su, do,

  1. mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/$USER where $USER is your username.
  2. chown -R $USER /nix/var/nix/{profiles,gcroots}/per-user/$USER
  3. nixos-rebuild switch

As usual, with some software, reproducibility goes out of the window. I needed to re-instantiate nextcloud-client and gnome-keyring. Trivial, but doesn’t work out of the box.