This repository gets you up and running with a flake that can build a Nix OS image for the Raspberry Pi.
This really basic example just comes with networking, docker, and SSH preconfigured.
- Clone the repo
git clone https://github.com/basalt-rs/nix-pi-base.git && cd nix-pi-base
- Setup
make setup-pathing # update paths in `flake.nix`
make setup-config # create configuration files
Make your configurations by modifying the following files:
config/networking.toml
config/users.toml
security.nix
- Build
Build according to your architecture, but different operating systems might have additional requirements. You'll likely want to use QEMU to cross-compile if necessary.
To build on x86 machines, you will need to set up QEMU with binfmt. I've included the Archlinux instructions for this.
- Build
make build
- Flash
# replace /dev/sda with your intended device target
make flash DEVICE=/dev/sda
- Eject
# You can do this manually to if you'd like or need.
make safe-eject
- Plug and Play
Booting up your Pi with your SD card inserted should cause your Pi to boot
into your NixOS image. If you're fully headless, use nmap
or arp-scan
to
find it on your network. Then you're good to SSH.
Note
If you end up rebuilding and reflashing, you may need to remove the device
from your known SSH hosts (~/.ssh/known_hosts
) or SSH may yell at you.
- Add
extra-platforms
to/etc/nix/nix.conf
extra-platforms = aarch64-linux
- Install Deps
sudo pacman -S qemu-user-static qemu-user-static-binfmt
- Build
You're good to build and flash as usual!
When you make changes to config files, you will need to update the nix lock:
make update-config