NixOS on ROCK 5

I finally received my Rock 5B, and I’d like to start learning NixOS. There’s no official support for NixOS, so I’d like to work on improving that. My research has lead me here:

https://nixos.wiki/wiki/NixOS_on_ARM#Porting_NixOS_to_new_boards

It indicates that if the board is supported by a U-Boot config, it can be fairly straightforward to build an image. However, it doesn’t appear that Rock 5B has been upstreamed.

That said, the Radxa github has a fork of U-Boot, which does contain what appears to be the correct board.

I’m guessing this fork is being used to build the official Rock 5 B images for Debian/Ubuntu/Android.

But considering many of the threads here about other distros say that full support isn’t mainlined, and because the official Ubuntu image has a special PPA for the linux kernel package coming from this Radxa fork (github.com/radxa/kernel), my guess is that building with the right U-Boot isn’t the only thing to do. What is the relationship between that kernel fork and this other overlays repo (github.com/radxa/overlays/tree/main/arch/arm64/boot/dts/rockchip/overlays), is this just the diff? Any direction here would be greatly appreciated.

Spoke to someone in the NixOS ARM matrix channel, and got some additional direction:

The most important excerpt:

Jonah: YMMV, basically a braindump of what I had at the time https://github.com/samueldr-wip/wip-nixos-on-arm/tree/wip/rock5
not october 27th, no, that is when I published this… ~july is when I got things going
it doesn’t include U-Boot, as this shouldn’t be dealt with by the operating system
https://github.com/samueldr/Tow-Boot/tree/wip/rock5-vendor
again, YMMV
nothing was updated from whatever commit this was made from by the vendor dumps in july
NOTE: flashing that build of U-Boot to SPI is not recommended, as the BSP U-Boot from that time can get itself confused easily and load things from the wront storage medium
which can make things look like they work, when they actually don’t

Those repos linked contain a Tow-Boot fork and a NixOS ISO builder. I’ll try using them and report back here for anyone else who finds it useful.

1 Like

My board arrived yesterday and I’ve already spent like 2 hours trying to understand how uboot and tow-boot work trying to make it build for rk3588. I’m very happy to see that there is a towboot fork (and even kernel derivations) for this device :slight_smile:
I’ll also write here my experience with TowBoot u-boot and NixOS.

1 Like

Managed to build a NixOS image using this repo:

https://github.com/jonahbron/wip-nixos-on-arm/tree/wip/rock5 (forked from https://github.com/samueldr-wip/wip-nixos-on-arm/tree/wip/rock5)

clone and cd into the repo, then run

nix-build -A radxa-rock5b.rootfs

There’s still more to figure out around how to get U-Boot and this NixOS image onto a eMMC

Also figured out how to build the u-boot platform firmware with this repo:

nix-build -A radxa-rock5b

That produces a result/shared.disk-image.img

I wrote that shared image to the eMMC module, then added another partition in the remaining free space with legacy_boot enabled using gparted. Then I wrote the NixOS image from the previous comment to the new partition with this command:

# Path to nixos image will be printed by the build command
stdcat /nix/store/sigmw8xx6fdiv1jr71gy9xpg12v58ll1-ext4-fs.img.zst-aarch64-unknown-linux-gnu | sudo dd of=/dev/sdb2 status=progress

Reference for this strategy: https://nixos.wiki/wiki/NixOS_on_ARM/UEFI#Shared_Firmware_Storage

With all of this, I’m able to boot NixOS from the eMMC module, but the system automatically reboots after briefly printing some logs. Working on building Nix with Raxda’s kernel fork instead, it should be newer and have more bugs fixed.

When building the NixOS build for ARM on the Radxa kernel, I’m getting this error:

/nix/store/qhvvivdi9pkvfpv7130sa71kpslkjv6f-bash-5.1-p16/bin/bash: line 1: mkimage: command not found

It seems like there’s a dependency of the build processing from the build configuration. Working on figuring out why exactly. I’ve also tried updating to the last nixpkgs, but that just changes the error I get to this instead:

Configuring config.h using configuration
Program xsltproc found: NO

meson.build:2413:2: ERROR: Program 'xsltproc' not found or not executable

Great Job Jonah. I want to suggest you to visit Radxa Discord too theres some infos there that might help.

1 Like

deps:
mtools
dtc
u-boot

ps.
xsltproc is from libxslt pkg

1 Like

I’m able to use jonah’s uboot and samueldr’s rootfs to boot nixos!

The key is to buy a DC12V to USB C cable and bypass PD handshake. The board need 12V1A at least to boot and run, otherwise there are some random panic during GPU initialization.

Here are some benchmark for fun:
https://browser.geekbench.com/v5/cpu/19203758

I too am officially able to get a working NixOS system running on my Rock5B. I’ve started a page for documenting the steps on the Nix wiki

https://nixos.wiki/wiki/NixOS_on_ARM/Rock5B

It links to the repo links and commands for building the platform firmware and the OS image, which can be assembled together following the general instructions here:

Summarized steps are

  1. Flash platform firmware image to eMMC
  2. Create a new unformatted partition at the end of the eMMC empty space
  3. Enable legacy_boot flag on new partition
  4. Flash the NixOS image to that partition

As an aside, I’m powering it with 5V directly to the 5V GPIO pin from a USB serial adapter.

After much debugging and collaboration with @aciceri, we’ve managed to get to the point where the system can be switched with a flake, and rebooted.

Instructions are here roughly

https://nixos.wiki/wiki/NixOS_on_ARM/Rock5B

2 Likes

I was able to get hardware acceleration working with kodi :grinning:: https://github.com/aciceri/rock5b-nixos

1 Like

Great news, can’t wait to try Kodi :slight_smile:

Has anyone tried running NixOS directly from NVMe? I have flashed the SPI with the bootloader for Armbian and the official Debian image, the one that is also working on my SD card, and it is working as intended.

With NixOS I have only made the SD card working so far. Initially I thought I should have added the “nvme” module at initrd.availableKernelModules (https://github.com/aciceri/rock5b-nixos/blob/e1099dd4a6be8018a5cc489fb2ee1d50e4e285a0/modules/kernel/default.nix#L20), but it appears that this was not enough.

Maybe I have to try to flash Tow-Boot directly on SPI, has anyone tried this?

I’m not sure if that line setting available modules is still needed, I had to add it because I remember that one of the default modules gave me problems, can’t even remember which one. By the way I can tell you that, without having nvme (this is my config, which uses rock5b-nixos flake under the hood) I was able to mount a NVME just connecting it, and right now I’m able to mount disks using a SATA adapter (but maybe this counts as SATA for the kernel, I have no idea).

Two further things:

  • In the flake I call it tow-boot but it’s uboot to be honest, I just use Tow-Boot Nix infrastructure to build it.
  • In general I would agree, having it on SPI would be better, but I remember that someone recommended to not do so with this board (yet I think). I believe it is because if you do something wrong you could brick it somehow and the only solution would be desoldering/resoldering the SPI.

I may have said several inaccuracies, I suggest you to join this Matrix room and ask folks (you can directly ask samueldr about tow-boot/uboot).

Hi jonah,

I looked at the page you made but I am confused and I am hoping you can help me out. I would like to put NixOS on my Rock Pi 5B but I’m not exactly sure what to make of the directions on that page. I’m looking to load NixOS onto a MicroSD card and then boot from that card if you can provide any advice.

Thank you!

@aciceri will you build any images for your https://github.com/aciceri/rock5b-nixos ?
If yes, I can add it to I made a Community Images Repository for rpi-imager

Currently I’m not using the rock5b-nixos repo anymore and instead I’m running the mainline 6.7 kernel since when it reached the nixpkgs repository (where NixOS packages and modules live). At the moment I also wanted to try to move uboot to the SPI.
I guess that you want an image that people can just flash to EMMCs or SDs and it just works, so I should include uboot in it, right?

Probably the only thing that still makes sense in the rock5b-nixos repository is the patched kodi (which I don’t use anymore).

PS: yeah I should really add a disclaimer somewhere in the README

1 Like

Someone achieved an NixOS for the orange pi
Idk if it works but to the interested:
Have a look here https://github.com/ryan4yin/nixos-rk3588/releases