Better RPI hardware support

Background

I’m in love with NixOS. Already moved most of my servers from Ubuntu LTS to NixOS stable. However, some niche use cases are yet to be flushed out.

Problem

The Raspberry Pi 4b, and SBCs in general, are first and foremost maker boards, meant to be tinkered with on a hardware level.

On the vendor-provided RasPI OS, you can configure everything hardware-related through an option in the /boot/config.txt, enabling things like SPI, or dropping the device in a peripheral mode in order for it to be used over a single USB-C cable by showing up as an “ethernet adapter”.

On NixOS, the recommended installation method is by flashing the Hydra pre-built SD Card images, as described HERE. Doing that means using the mainline kernel by default, along with uboot as a bootloader. However, doing that would invalidate a significant portion of the Wiki page specific to Raspberry Pi 4 configuration found HERE. While some things like configuring GPIO permissions to be user-accessible work, getting SPI working does not. Talking to people on the Nix on ARM Matrix channel, I reached the conclusion that the bulk of that Wiki page assumes that the user is using the vendor-supplied kernel, and not the main one.

In addition, the SPI section refers to a dtso file, linking to device tree descriptors provided by the RPi foundation. However, if you actually follow the link, you’ll get a binary object file instead.

Question

What would be the requirements to implement the functionality of the RPi Foundation’s config.txt in a nix-compatible way? something along the lines of

hardware.raspberry-pi-4.spi = {
  enable = true;
  userControlled = true;
};

for enabling SPI and adding the udev rules to give permissions to a group called spi

For example, maybe the customizations done to the Linux kernel by the RPi foundation can be loaded as DKMS modules based on the enabled options.

Note: this is less of a direct question, and more of an open discussion. My ultimate goal is to be able to contribute to Nix support on the RPi4, but Nix-specific learning resources are sparse. All discussions are welcome.