This a post on my "Noframes" wiki.
Squirrel! Cardputer ADV — Nix flake (illustration)
Table of Contents
This is an LLM ass-isted document, as are all in the ass/ subdirectory.
Of these, here in the dump/ subdirectory I keep the sloppy & doubtful ones.
I keep these as learning materials for myself, yet to be went thru.
Illustration and reference for wrapping a third-party vendor tree (M5 UIFlow / Cardputer ADV MicroPython) plus an application (Squirrel!) in Nix — without claiming a supported fork of either upstream or a turnkey product.
BTW this build didn't work. Black screen.
And, duh, we ditched the USB CDC so no MicroPython REPL.
Those instructions aren't successful.
What this build is for
Squirrel! is open firmware for a pocket notes / todos stack on the M5Stack Cardputer ADV (ESP32-S3 + keyboard). Data lives on SD; optional sync to a T-Watch is Bluetooth, not USB mass-storage or TinyUSB gadget modes. Upstream ships build_firmware.py: clone vendor repos, stage the app from ports/cardputer_adv/port.toml, synthesize a *_Squirrel board, run make pack, flash or copy .bin to SD.
The flake here is a narrow slice of that story:
- One port (Cardputer ADV), one output (packed
uiflowimage suitable for M5Launcher-style SD install). - No interactive flash/REPL/T-Watch tooling in Nix — only the compile-and-pack path.
- Declared inputs (Squirrel git rev, Cardputer firmware git rev, IDF 5.4.2, registry component hashes) so a machine with Nix can rebuild without “whatever happened to be in
managed_components/last Tuesday.”
It is useful as a pattern reference for: offline ESP-IDF component pins, IDF_COMPONENT_MANAGER=0, duplicating a vendor board directory with sed, and checking firmware blobs in checkPhase.
Pipeline (conceptual)
flake inputs (Squirrel app, Cardputer vendor tree, esp-dev toolchains)
│
├─► cardputer-adv.nix ──► port_config.py policy, board names, patch list
├─► stage-app.nix ──► filtered Squirrel! tree for freezing
├─► managed-components.nix ──► Espressif zip FODs (no network at compile time)
│
└─► package.nix
fetchgit IDF vendor + copy m5stack tree
make patch / littlefs / mpy-cross
synthesize M5STACK_CardputerADV_Custom_Squirrel
make BOARD=… pack
→ squirrel.bin (~6.4 MiB packed flash image)
Upstream build_firmware.py still owns product ergonomics (flash, device setup, multi-port). The Nix layer owns reproducibility: same inputs, same graph, repeatable full rebuilds on a Nix-capable host.
Design choices worth reading for
Dual ESP-IDF tree. Nixpkgs esp-idf-full supplies toolchains and idf.py env; a separate fetchgit of Espressif’s repo (with submodules) is copied into the build because the trimmed nixpkgs tree is missing pieces the M5 Makefile expects.
Component manager off. Vendor idf_component.yml files are not resolved at build time. Registry artifacts are prefetched in managed-components.nix and copied into components/espressif__*; CMake is patched where the manager would have wired REQUIRES (e.g. mdns, quirc).
Squirrel board ≠ vendor board. The Custom Cardputer ADV board enables TinyUSB CDC and frozen M5 USB helpers. Squirrel does not use USB for sync; this overlay strips TinyUSB, uses USB Serial/JTAG for console on the S3, and drops frozen M5 libs/usb. That avoids registry tinyusb / esp_tinyusb and IDF 5.4 header mismatches in dcd_esp32sx.c when soc/usb_periph.h no longer carries register macros — at the cost of custom sdkconfig and manifest lines.
Camera stack still links. M5’s shared CMakeListsDefault.cmake always pulls esp32-camera (and thus esp_jpeg in the offline set) even though Cardputer ADV has no camera. Vendor cmake baggage, not Squirrel features.
Store and I/O. Full firmware rebuilds are heavy on /nix/store. The driver uses cp -a --reflink=auto on CoW filesystems to avoid duplicating large IDF trees every attempt.
What you do not get in this folder. No squirrel.bin binary (artifact comes from nix build). No flash scripts bundled here; pins are fixed in flake.lock and may lag upstream main.
Layout
All sources: ass/SquirrelNixFlake/.
flake.nix
- Flake entry: wires inputs to derivations.
esp-dev: Xtensa toolchain +esp-idf-fulloverlay (IDF 5.4.2 pin).squirrel/cardputer-firmware: non-flake GitHub sources (app + vendorm5stack/).- Outputs
firmware(default),stagedApp,managedComponents;checks.defaultequals firmware.
flake.lock
- Frozen input graph.
- Exact Squirrel and Cardputer-adv-micropython commits for this snapshot.
- Substitutes for ad-hoc “note the SHAs in README” discipline.
cardputer-adv.nix
- Pure Nix policy module (no network).
- Parses
port.toml/features.tomllikebuild_firmware.pywhen generatingport_config.py. - Computes which Squirrel subtrees are frozen (
rsyncExcludes) from hardware + feature gates. - Names
boardBase/boardSquirreland collectsfirmware_patches/*.patchpaths forgit apply.
- Parses
stage-app.nix
- Small derivation: materialize “what gets frozen into MicroPython.”
- Copies
Squirrel!minus dev/tooling paths. - Injects generated
port_config.pyand a minimalsq_info.py(BUILD = "nix").
- Copies
managed-components.nix
- Offline mirror of Espressif Component Registry zips.
- Pattern: each component
fetchurl+ unzip intomanaged_components/espressif__*. - Shows which blobs Cardputer ADV needs with manager off (ADF/audio path, mdns, JPEG for shared camera cmake, etc.).
- Pattern: each component
package.nix
- The long build script: vendor Makefile inside Nix.
- Board synthesis (
cpbase board →*_Squirrel, manifest freeze line, USB/console overlays). make packorchestration, artifact pick (uiflow*.bin), sanity checks (ROM magic, partition table signature).- The place to compare with a one-off
build_firmware.pyrun on a dirty tree.
- Board synthesis (
Running the flake
From a machine with Nix and enough disk:
cd …/ass/SquirrelNixFlake
nix build -L .#firmware
ls -l result/bin/squirrel.bin
Flashing and SD layout follow Squirrel and M5Launcher documentation; rebuilding is optional once you have read the sources.
Upstream
- Squirrel!: https://github.com/aparatowo/Squirrel
- Cardputer ADV MicroPython vendor tree: https://github.com/TheRealHaoLiu/cardputer-adv-micropython
- ESP-IDF Nix tooling: https://github.com/mirrexagon/nixpkgs-esp-dev