NixOS is supported on the Pi 4 as an aarch-64 image. Read more here.
Currently, the builds running on Hydra are broken past linux kernel version 5.10, so we'll stick to that version.
Look for a successfully building image on the Hydra website.
(Check that you're downloading the 5.10 Linux kernel.)
For example, this guide was built with this build: https://hydra.nixos.org/build/157989162
The image is compressed with zstd. Download and run unzstd to uncompress, or with Nix nix-shell -p zstd --run "unzstd -d <IMG-NAME>.img.zst".
Insert an SD card, find its device with lsblk -f and, using /dev/sdb as an example device, flash the image onto it: sudo dd if=<IMG-NAME>.img of=/dev/sdb bs=4096
Let this run and be sure to unmount the drive cleanly.
Insert the flashed SD card into your Pi and boot it.
This should drop you into a shell.
Jump into root with sudo -i.
Now we're going to build a configuration and install a new system.
Run nixos-generate-config.
This creates a configuration.nix and hardware-configuration.nix under /etc/nixos.
Open configuration.nix and add the following (a template of this is by default commented out near the end of the file).
# Enable the OpenSSH server.
services.openssh = {
enable = true;
permitRootLogin = "yes";
};
Your Pi needs to know how to boot. We'll also need the latest kernel packages. Add the following to hardware-configuration.nix.
boot = {
loader = {
grub.enable = false;
raspberryPi.enable = true;
raspberryPi.version = 4;
};
kernelPackages = pkgs.linuxPackages_rpi4;
};
This will set up the correct boot firmware under /boot when you install.
Next, check whether a fileSystems setting was autogenerated in hardware-config. If not, add something like the following. The default aarch64 images label the filesystem NIXOS_SD usually, but yours may be different.
fileSystems."/".device = "/dev/disk/by-label/NIXOS_SD";
since we added these configs under the /etc/nixos/ path, we'll specify the root for the install, run
nixos-install --root /.
If all went well you will be prompted to create a password for the root user. If successful, run reboot.
Now you have a working NixOS system. Time to install nix-bitcoin, which we will do from your home machine and deploy nix-bitcoin onto your Pi. Nothing to add here, you can follow the deploy instructions from the official nix-bitcoin docs.
If you run into errors during the deploy, ssh into your Pi and look under /var/src. This folder should include the deployed configuration. You can run nixos-rebuild -I /var/src switch to rebuild your system with this new configuration. You can do this at any time.