NixOS on ARM/Raspberry Pi: Difference between revisions

imported>Bct
Kernel selection
imported>Bct
Device tree overlays
Line 340: Line 340:


Using the 3.3v serial port via the pin headers (exact location depends on hardware version) will get u-boot output and, when configured, a Linux kernel console.
Using the 3.3v serial port via the pin headers (exact location depends on hardware version) will get u-boot output and, when configured, a Linux kernel console.
== Device trees ==
Raspberry Pi add-on hardware often requires a device tree overlay. On other OSes this is usually set up using a <code>dtoverlay=</code> option in config.txt on the firmware partition. This approach can be made to work on NixOS with some combination of bootloader and kernel, but it may be easier and more explicit to use NixOS' <code>hardware.deviceTree</code> option to compile the overlay directly into the device tree.
A device tree config looks something like this:
<syntaxhighlight lang="nix">
hardware.deviceTree = {
    enable = true;
    overlays = [
      {
        name = "hifiberry-dacplus";
        dtsText = ''
/dts-v1/;
/plugin/;
/ {
      compatible = "brcm,bcm2835";
// ... etc.
''
      }
    ];
  };
</syntaxhighlight>
This will apply the overlay to all <code>.dtb</code> files with a matching <code>compatible</code> line.
After rebooting you can check if the overlay has been applied by looking for it in the output of <code>dtc --sort /proc/device-tree</code>.
dtoverlay may fail with <code>FDT_ERR_NOTFOUND</code> on some Raspberry Pi device tree overlays. In this case dtmerge should be used instead. There is a Nix overlay to use dtmerge for applying device tree overlays: https://github.com/NixOS/nixos-hardware/blob/429f232fe1dc398c5afea19a51aad6931ee0fb89/raspberry-pi/4/apply-overlays-dtmerge.nix


== Troubleshooting ==
== Troubleshooting ==