Skip to main content

Installing NixOS on Raspberry PI 3B

This is assumed that you already have access to a running NixOS System..

Initial Configuration

  • Download SD Image from Hydra.
  • Write the image to the SD Card
 dd if=nixos-sd-image-23.11pre498616.6b3d1b1cf13-aarch64-linux.img of=/dev=sdd bs=4M
  • Allow main development system to build derivations off of its machine emulating aarch64 architecture so as to not choke out the Raspberry PI. to main development system to build derivations off the machine to not choke out the PI.
# configuration.nix

boot.binfmt.emulatedSystems = [ "aarch64-linux" ];

Build Configuration

  • Build the configuration on your workstation and take note of the store path that is ouputted.
nix build .#nixosConfigurations.beer.config.system.build.toplevel --print-out-paths

# Example Path
/nix/store/randomarbitraryhashavc-nixos-system-beer-23.05.20230626.ab3331

Initial Install

  • Boot SD Image on PI and make sure SSH is accessible

  • Get hardware information nixos-generate-config

  • Move around hardware.nix and configure other settings (configure.nix or flake repo, what have you)

  • Copy the built files over to the PI

nix copy [the path above] --to ssh://root@[pi]
  • Install NixOS on the PI
# configuration.nix 
nixos-install --root / --system [the path above]

# Flakes
nixos-install --root / --flake /tmp/system/nixos#beer --system [the path above]

Subsequent Installs

Use the remote rebuild functionality of nixos-rebuild

NIX_SSHOPTS="-t -p 22" nixos-rebuild switch --flake .#beer --target-host remoteuser@beer --use-remote-sudo
# config.txt
# See /boot/overlays/README for all available options

initramfs initramfs-linux.img followkernel

dtoverlay=vc4-fkms-v3d # or vc4-kms-v3d or nothing
hdmi_force_hotplug=1
hdmi_timings=2560 0 48 32 80 1080 0 7 20 12 0 0 0 52 0 159838855 7
hdmi_group=2
hdmi_mode=87
hdmi_drive=2
framebuffer_width=2560
max_framebuffer_width=2560
framebuffer_height=1080
hdmi_pixel_freq_limit=160000000

display_auto_detect=1

# Uncomment to enable bluetooth
#dtparam=krnbt=on

[pi3]
dtoverlay=rpi3-hdmi

[pi4]
# Run as fast as firmware / board allows
arm_boost=1