2.1 KiB
2.1 KiB
Laser NixOS
Nix expressions for building a NixOS image for the Raspberry Pi 3 controlling the laser cutter in CCCHH.
TL;DR
export \
MACHINE=raspberry-pi-3 \
SD_CARD=/dev/sda \
NIXPKGS_REV=dba4149
nix-build -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/${NIXPKGS_REV}.tar.gz" -I machine=machines/$MACHINE --out-link out-links/$MACHINE
Building
The ISO must be built by emulation if you are not building on an aarch64 machine. Build your host NixOS with the following in the configuration.
boot.binfmt.emulatedSystems = [
"aarch64-linux"
];
Machines
Select one of the machines and set the environment variable.
export MACHINE=raspberry-pi-3
nixpkgs
Versions
Select a nixpkgs version and set the enviroment variable.
export NIXPKGS_REV=dba4149
It's recommended to set it to one of the revision hashes from the table below.
But you can also set it to a branch name like nixos-24.05
.
ref | rev | date |
---|---|---|
nixos-24.05 | dba4149 |
2024-11-07 |
Build
nix-build -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/${NIXPKGS_REV}.tar.gz" -I machine=machines/$MACHINE --out-link out-links/$MACHINE
Flashing
Select the correct block device and set the environment variable.
export SD_CARD=/dev/sda
sudo sh -c "zstd -dcf out-links/$MACHINE/sd-image/*.img.zst | dd status=progress bs=64k iflag=fullblock oflag=direct of=$SD_CARD && sync && eject $SD_CARD"
Deployment
For deploying new images without reflashing, you can use NixOps.
nix-shell -p nixops_unstable_minimal
Since stable NixOps reuqires Python2, we use the unstable version.
[nix-shell:~]$ nixops --version
NixOps 1.7-unstable-2024-02-28-pre-08feccb
Create
nixops create -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/${NIXPKGS_REV}.tar.gz" -I machine=machines/$MACHINE
Deploy
nixops deploy -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/${NIXPKGS_REV}.tar.gz" -I machine=machines/$MACHINE