# Guix + OpenWrt Userland on MikroTik RB5009 — Project Plan Goal: run a GNU Guix system on an off-the-shelf MikroTik router, reusing OpenWrt's hardware enablement (kernel patches, DTS, boot chain) and packaging OpenWrt's userland (ubus, uci, netifd, …) as Guix packages. --- ## 1. Hardware choice MIPS is **not** required — and should be avoided. Guix has no real 32-bit MIPS support, and those devices have far too little flash for a glibc-based Guix system. | Class | Examples | Verdict | |---|---|---| | 32-bit MIPS | hAP lite, hAP ac lite, hAP ac³, hEX / hEX S (MT7621) | Avoid | | 32-bit ARM | hAP ac² (IPQ4018), RB4011 | Possible, storage tight | | 64-bit ARM | **RB5009**, hAP ax²/ax³, CCR2004 | Best fit | > Verify exact SoC/specs per model before buying — MikroTik revises hardware under the same names. **Target: RB5009** — Marvell Armada 7040 (aarch64), 1 GB RAM, 1 GB NAND. Why: OpenWrt already solved the hard parts. RouterBoot only boots ELF images (no FIT), so OpenWrt chainloads a U-Boot port for the RB5009, which then boots normally. Device support (incl. the RB5009UPr+S+IN variant) is merged upstream in OpenWrt. PoE is still incomplete under OpenWrt. --- ## 2. Known constraints - **Size:** Guix uses glibc and has large store closures. Keep the system minimal (no `%base-packages` bloat); budget a few hundred MB of the 1 GB NAND. - **Init model clash:** OpenWrt = procd + UCI + hotplug; Guix = Shepherd + Scheme. Pick one source of truth (recommended: Guix). - **Firmware/blobs:** some may conflict with Guix's free-software policy (see Nonguix). - **Recovery:** RouterOS netinstall can always restore the device — experiment freely. --- ## 3. Build plan ### Phase 0 — Prototype in QEMU (no hardware risk) - Use `qemu-system-aarch64 -M virt`. - Get the Guix system + OpenWrt userland (Phases 3–4) working here first. ### Phase 1 — Boot chain - Reuse OpenWrt's chain unchanged: **RouterBOOT → U-Boot (ELF) → kernel**. - Configure U-Boot to load kernel + initrd from a UBI volume on NAND. ### Phase 2 — Kernel - Write a Guix `linux` package variant using OpenWrt's `target/linux/mvebu` (`cortexa72` subtarget) patches, RB5009 DTS, and kernel config. - Must include: - QCA8081 2.5 GbE PHY support - MikroTik RouterBoot soft_config sysfs driver - UBI / UBIFS built-in - mvpp2 + DSA switch support ### Phase 3 — Root filesystem - UBIFS volume on NAND holds `/gnu/store`. - Build: `guix system image --target=aarch64-linux-gnu router.scm` (or natively on an aarch64 host). - Write the rootfs into the UBI volume (not a raw disk image). ### Phase 4 — Package OpenWrt userland for Guix Small CMake projects, straightforward to package: - [ ] `libubox` - [ ] `ubus` - [ ] `uci` - [ ] `ucode` - [ ] `netifd` - [ ] `odhcpd` - [ ] `firewall4` (on nftables) - [ ] (optional) LuCI Init strategy — choose one: - **Shepherd as PID 1** (recommended): Shepherd services run `ubusd`, `netifd`, etc. Keeps Guix generations/rollbacks intact. - **procd as PID 1**: more authentic, but fights Guix's activation model. ### Phase 5 — Configuration - Generate `/etc/config/*` (UCI files) from Scheme in the `operating-system` declaration. - Decide deliberately: declarative (LuCI/`uci set` edits are overwritten on reconfigure) vs. mutable config. ### Phase 6 — Upgrades - Replace `sysupgrade` with `guix deploy` or `guix system reconfigure` over SSH. - Generations provide rollback. --- ## 4. Installing on the RB5009 (OpenWrt method, for reference) 1. In RouterOS: `/system/routerboard/settings/set boot-device=ethernet` 2. Serve the initramfs ELF via BOOTP/TFTP (e.g. dnsmasq); connect via a LAN port initially (port 1 defaults to WAN). 3. From the booted initramfs: ```sh echo cfg > /sys/firmware/mikrotik/soft_config/boot_device echo 1 > /sys/firmware/mikrotik/soft_config/commit ``` 4. Flash the system to NAND (OpenWrt uses `sysupgrade`; for Guix, write the UBI volumes). Follow the current OpenWrt wiki page for exact steps — they've changed over time. --- ## 5. Next steps 1. Set up aarch64 cross-build or native build host with Guix. 2. Draft Guix package definitions for `libubox`, `ubus`, `uci`. 3. Boot a minimal Guix aarch64 system in QEMU with those services. 4. Pull OpenWrt's mvebu kernel patches + RB5009 DTS into a Guix kernel package. --- ## References - OpenWrt RB5009 wiki: https://openwrt.org/toh/mikrotik/rb5009ug_s_in - OpenWrt forum thread: https://forum.openwrt.org/t/add-support-for-mikrotik-rb5009ug/104391 - U-Boot RB5009 commit: https://git.openwrt.org/14bf60deb884b9466dc172ec5d12e5f515046a4a - Early RB5009 port (adron-s): https://github.com/adron-s/openwrt-rb5009 - RB5009 PoE status: https://forum.openwrt.org/t/mikrotik-rb5009upr-s-in-poe-not-usable-under-openwrt-despite-hardware-support/251556 - Guix manual: https://guix.gnu.org/manual/