Nixos

Updated: November 3, 2024

The nixos process of creating the image for pi 3/4/5/400


Future Goals (created through flake)

Either boot from netboot or iSCSI
Either nixos oci containers or k8s
setup motd


Table of Contents

Preparation

Use RaspberryOS to setup settings in the firmware if ≤ pi3

# get latest software and upgrade
sudo apt update && sudo apt upgrade -y

# update the eprom
sudo rpi-eeprom-update -d -a

# set localization and boot
sudo raspi-config
  # 5 Localisation Options » L1 Locale » en_US.UTF-8 UTF-8 (select with spacebar) » OK
  # 5 Localisation Options » L2 Timezone » US » Eastern
  # 6 Advanced Options » A7 Bootloader Version » E1 Latest » OK » no
  # 6 Advanced Options » A6 Boot Order » B2 USB Boot » Finish » yes, reboot

# gather information and write it down somewhere
sudo fdisk -l || lsblk || diskutil list

SD Card

Hydra aarch64-linux 24.05 Images
Hydra aarch64-linux Unstable Images
Images download as .zst need to be decompressed before writing to installation device!

# decompress image before installing
nix-shell -p zstd --run "unzstd <img-name>.img.zst"

With the image ready we can place it onto SD card

# find device for image, I like to use duf
sudo fdisk -l || lsblk || diskutil list

# unmount the disk so we can format (using MacOS here otherwise use fdisk)
diskutil unmountDisk /dev/<disk>

# format for pi use we want FAT32 (ms-dos)
diskutil eraseDisk FAT32 <name> MBR /dev/<disk>
diskutil eraseDisk FAT32 PI400 MBR /dev/disk4

# copy image to device
sudo dd if=nixos-sd-image-aarch64-linux.img of=/dev/disk4 bs=4M status=progress

Building the Image

There are tools and snippets to include in the image.

# package of rpi tools
libraspberypi

# enable bluetooth
services.bluetooth.enable = true;

# enable ethernet
networking.interfaces.eth0.enable = true;

# disable wifi
networking.wireless.enable = false;

# disable audio
sound.enable = false;

# disable GPIO
services.gpio.enable = false;

With these settings included in flake:

# clone flake onto the pi ensuring above settings considered
git clone git://github.com/<username>/<flake>.nix

# afterward try a nixos-rebuild switch

Test Write && Read

dd if=/dev/zero of=./speedTestFile bs=20M count=5 oflag=direct
dd if=./speedTestFile of=/dev/zero bs=20M count=5 oflag=dsync

Desktop

If we no longer want a headless experience we can add desktop
by configuring the flake to include:

services = {
  # NOTE: X11
  xserver = {
    enable = true;
    displayManager.startx.enable = true;  # could use lightdm instead
    windowManager.xfce.enable = true; # gnome || kde || lxqt || xfce
  };
  # NOTE: Hyprland (make above settings false)
  hyprland.enable = true;
  wayland.enable = true;
};

# NOTE: hyprland package will need to be installed as a package
environment.systemPackages = with pkgs; [ hyprland ];