Nix Derivations
The nix/ directory contains four derivations that produce the build artifacts. Each is called from flake.nix via
pkgs.callPackage.
Build Pipeline
flowchart LR
SQUASHFS["squashfs.nix"] --> ROOTFS["rootfs.squashfs"]
BOOTSCRIPT["boot-script.nix"] --> BOOTSCR["boot.scr"]
ROOTFS --> IMAGE["image.nix"]
BOOTSCR --> IMAGE
IMAGE --> IMGOUT["flashable .img"]
ROOTFS --> RAUCBUNDLE["rauc-bundle.nix"]
BOOTSCR --> RAUCBUNDLE
RAUCBUNDLE --> BUNDLEOUT["signed .raucb for OTA"]
squashfs.nix
Purpose: Builds a read-only squashfs image from the full NixOS system closure.
Function signature:
{ stdenv, squashfsTools, closureInfo, nixosConfig, maxSquashfsSize }:
| Parameter | Source | Description |
|---|---|---|
nixosConfig | rock64System.config | Evaluated NixOS configuration |
maxSquashfsSize | flake.nix (1 GB) | Maximum allowed image size |
Delegates to: scripts/build-squashfs.sh
Build steps:
- Compute all Nix store paths from
closureInfoofsystem.build.toplevel - Copy all store paths into a pseudo-root directory
- Create
/initand/sbin/initsymlinks to the NixOS init - Create empty mount-point directories (
/proc,/sys,/dev,/run,/etc,/var,/tmp, etc.) - Run
mksquashfswith zstd compression (level 19), 1 MB block size - Fail if the image exceeds
maxSquashfsSize
Output: $out/rootfs.squashfs
Compression options:
- Algorithm: zstd (level 19)
- Block size: 1 MiB (1048576)
- No xattrs
- All files owned by root
rauc-bundle.nix
Purpose: Builds a signed RAUC bundle containing boot (kernel + initrd + DTB + boot.scr) and rootfs (squashfs) images.
Function signature:
{ stdenv, rauc, dosfstools, mtools, squashfsTools,
nixosConfig, squashfsImage, bootScript, signingCert, signingKeyPath, caCert }:
| Parameter | Source | Description |
|---|---|---|
nixosConfig | rock64System.config | Provides kernel/initrd/DTB paths |
squashfsImage | packages.squashfs | The squashfs derivation output |
bootScript | packages.boot-script | Compiled boot.scr |
signingCert | ./certs/dev.signing.cert.pem | RAUC signing certificate |
signingKeyPath | ./certs/dev.signing.key.pem | RAUC signing private key |
caCert | ./certs/dev.ca.cert.pem | CA certificate for verification |
Delegates to: scripts/build-rauc-bundle.sh
Build steps:
- Create a 128 MB vfat image (
boot.vfat) - Copy kernel
Image,initrd, DTB, andboot.scrinto it using mtools - Copy
rootfs.squashfsinto the bundle directory - Generate
manifest.raucmwithcompatible=rock64and image definitions - Sign and package with
rauc bundle
Output: $out/rock64.raucb
Manifest structure:
[update]
compatible=rock64
version=<nixosConfig.system.nixos.version>
[image.boot]
filename=boot.vfat
type=raw
[image.rootfs]
filename=rootfs.squashfs
type=raw
boot-script.nix
Purpose: Compiles the U-Boot boot script from source (boot.cmd -> boot.scr).
Function signature:
{ stdenv, ubootTools, buildId }:
| Parameter | Source | Description |
|---|---|---|
buildId | flake.nix | Build identifier echoed during U-Boot boot |
Build step:
mkimage -C none -A arm64 -T script -d boot.cmd boot.scr
Output: $out/boot.scr (compiled) and $out/boot.cmd (source copy)
image.nix
Purpose: Assembles the complete flashable disk image for eMMC provisioning.
Function signature:
{ stdenv, dosfstools, mtools, util-linux,
ubootRock64, nixosConfig, squashfsImage, bootScript }:
| Parameter | Source | Description |
|---|---|---|
ubootRock64 | nixpkgs | U-Boot package for Rock64 |
nixosConfig | rock64System.config | Provides kernel, initrd, DTB |
squashfsImage | packages.squashfs | Squashfs derivation |
bootScript | packages.boot-script | Compiled boot.scr |
Delegates to: scripts/build-image.sh
Image layout (total ~1170 MiB sparse):
| Offset | Size | Content | Filesystem |
|---|---|---|---|
| 0 | 16 MB | U-Boot raw | – |
| 16 MB | 128 MB | boot-a | vfat |
| 144 MB | 1024 MB | rootfs-a | squashfs |
| 1168 MB | remaining | unallocated | – |
Output: $out/atomicnix-<series>.img
The image name is derived from the pinned NixOS release series (e.g., atomicnix-25.11.img). The image leaves the
remaining eMMC space unallocated so initrd systemd-repart can create boot-b, rootfs-b, and /data on first
boot.
GPT partition types: Boot partitions use the xbootldr GUID (BC13C2FF-...). Rootfs partitions use the Linux root
aarch64 GUID (B921B045-...), which is the architecturally correct type for aarch64 root filesystems.
U-Boot raw writes:
idbloader.imgat sector 64 (32 KB)u-boot.itbat sector 16384 (8 MB)
boot-a contents: kernel Image, initrd, DTB (rockchip/rk3328-rock64.dtb), boot.scr