# Laser NixOS Nix expressions for building a NixOS image for the Raspberry Pi 3 controlling the laser cutter in CCCHH. ## TL;DR ```shell 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. ```nix boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; ``` ### Machines Select one of the [machines](./machines/) and set the environment variable. ```shell export MACHINE=raspberry-pi-3 ``` ### `nixpkgs` Versions Select a [nixpkgs](https://github.com/NixOS/nixpkgs/) version and set the enviroment variable. ```shell 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 ```shell 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. ```shell 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](https://github.com/NixOS/nixops). ```shell nix-shell -p nixops_unstable_minimal ``` Since stable NixOps reuqires Python2, we use the unstable version. ```shell [nix-shell:~]$ nixops --version NixOps 1.7-unstable-2024-02-28-pre-08feccb ``` ### Create ```shell nixops create -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/${NIXPKGS_REV}.tar.gz" -I machine=machines/$MACHINE ``` ### Deploy ```shell nixops deploy -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/${NIXPKGS_REV}.tar.gz" -I machine=machines/$MACHINE ```