How to install NixOS on a Raspberry Pi 3b

I had a hard time figuring out how to install NixOS on my old Raspberry Pi 3B, so here’s a step-by-step guide.

First confusion: Which Raspberry Pi do I have?

The first thing I struggled with was figuring out exactly which Raspberry Pi model I had. Eventually, I found this command:

$ cat /sys/firmware/devicetree/base/model
Raspberry Pi 3 Model B Rev 1.2

which confirmed which version I had.

Second confusion: How should the SD card be formatted?

When I found an SD card to use for the Raspberry Pi, I formatted it first with an ext4 file system. I wasted some time trying to copy various ISO’s over to that one, only to see none of them boot on the Pi. In the end I formatted the card with a fat32 file system, and that worked.

Third confusion: Which architecture does Raspberry Pi 3B have?

The third thing I struggled with was understanding which architecture I needed to use. A few years ago I installed RetroPie on my Raspberry Pi, and when I inspected which architecture was running on my Pi, I saw this:

$ uname -a
Linux retropie 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv71 GNU/Linux

This made me think that I needed to use armv7. In addition, if you google “raspberry pi nixos”, then you likely find this page, which shows a nice overview of the architectures of the different Raspberry Pi versions. For Raspberry Pi 3, the overview says “AArch64 + armv7”, which made me more sure that I needed to use armv7.

Long story short: I wasted hours trying various armv7-iso’s, none of which booted on my pi (in some of my attempts this may have been due to my second confusion above). In the end I asked for help on the NixOS discourse (so many helpful people there!), where I learned that I should just try an aarch64 iso. And that worked!

What worked, step-by-step

  1. Download an ISO from https://nixos.wiki/wiki/NixOS_on_ARM#Installation (see the “SD card images (SBCs and similar platforms)” heading)

  2. Plug in your SD card and run lsblk to see where your card is mounted. You can see my results below:

$ lsblk
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
sda                   8:0    1  29.7G  0 disk
├─sda1                8:1    1    57M  0 part
└─sda2                8:2    1  29.7G  0 part
...

Here you can see that my SD card was mounted as /dev/sda.

  1. I found this guide for how to format SD cards on linux, and I did it like this:
$ nix-shell -p parted

[nix-shell:~]$ sudo parted /dev/sda --script -- mklabel msdos

[nix-shell:~]$ sudo parted /dev/sda --script -- mkpart primary fat32 1MiB 100%

[nix-shell:~]$ sudo mkfs.vfat -F32 /dev/sda1
mkfs.fat 4.1 (2017-01-24)

[nix-shell:~]$ sudo parted /dev/sda --script print
Model: Generic USB SD Reader (scsi)
Disk /dev/sda: 31.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  31.9GB  31.9GB  primary  fat32        lba

Note that I went into a nix shell with the parted executable there, as I didn’t already have that available on my system. If you are doing this from a non-NixOS system, you need to get parted (or another tool) in another way.

  1. Use dd to copy the NixOS iso onto the SD card:
$ sudo dd if=/home/stian/nixos-sd-image-21.11.336755.efea022d6fe-aarch64-linux.img of=/dev/sda bs=4M conv=fsync status=progress
3196059648 bytes (3.2 GB, 3.0 GiB) copied, 1 s, 3.2 GB/s
873+1 records in
873+1 records out
3664646144 bytes (3.7 GB, 3.4 GiB) copied, 265.032 s, 13.8 MB/s
  1. Put the SD card into the Raspberry Pi and have fun with NixOS!

Comments

comments powered by Disqus