Jump to content

NixOS on ARM/Raspberry Pi 4: Difference between revisions

Heading levels, grammar
imported>Bluk
No edit summary
imported>Skylark
(Heading levels, grammar)
Line 27: Line 27:
|}
|}
</div>
</div>
The Raspberry Pi family of devices is a series of single-board computers made by the Raspberry Pi Foundation. They are all based on Broadcom System-on-a-chip (SoCs).  
The Raspberry Pi family of devices is a series of single-board computers made by the Raspberry Pi Foundation. They are all based on Broadcom System-on-a-chip (SoCs).


== Status ==
== Status ==
Line 47: Line 47:
Using <code>nixos-generate-config</code> will generate the required minimal configuration.
Using <code>nixos-generate-config</code> will generate the required minimal configuration.


For better GPU Support and some deviceTree quirks add the nixos-hardware channel:
For better GPU support and some deviceTree quirks add the nixos-hardware channel:


<code>
<code>
Line 87: Line 87:
</nowiki>}}
</nowiki>}}


Now reboot the device so it can update the firmware from boot partition.
Now reboot the device so it can update the firmware from the boot partition.


=== GPU support ===
=== GPU support ===
Line 125: Line 125:
}
}
</nowiki>}}
</nowiki>}}
==== Tools ====
=== Tools ===


The raspberry tools are available in the <code>libraspberrypi</code> package and include commands like <code>vcgencmd</code> to measure temperature and CPU frequency.
The raspberry tools are available in the <code>libraspberrypi</code> package and include commands like <code>vcgencmd</code> to measure temperature and CPU frequency.


==== Audio ====
=== Audio ===


In addition to the usual config, you will need to enable hardware audio support:
In addition to the usual config, you will need to enable hardware audio support:
Line 139: Line 139:
</nowiki>}}
</nowiki>}}


=== Using GPIO pins as non root ===
=== Using GPIO pins as non-root ===


By default, the GPIO pins are enable, but can only be accessed by the root user.
By default, the GPIO pins are enabled, but can only be accessed by the root user.
This can be address by adding a [https://wiki.archlinux.org/title/Udev udev] rule to your configuration that changes the owner ship of <code>/dev/gpiomem</code> and the other required devices.
This can be addressed by adding a [https://wiki.archlinux.org/title/Udev udev] rule to your configuration that changes the ownership of <code>/dev/gpiomem</code> and the other required devices.


The following code adds a group <code>gpio</code> and adds the user <code>mygpiouser</code> to that group.
The following code adds a group <code>gpio</code> and adds the user <code>mygpiouser</code> to that group. You probably want to put your own user name here.
You probably want to put your own user name here.


The <code>extraRules</code> change the owner of <code>gpiomem</code> and all other files needed for GPIO to work to <code>root:gpio</code> and changes the permissions to <code>0660</code>.
The <code>extraRules</code> changes the owner of <code>gpiomem</code> and all other files needed for GPIO to work to <code>root:gpio</code> and changes the permissions to <code>0660</code>.
Therefore, the root user and anyone in the gpio group can now access the GPIO pins.
Therefore, the root user and anyone in the gpio group can now access the GPIO pins.


Line 157: Line 156:
   services.udev.extraRules = ''
   services.udev.extraRules = ''
     SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio",MODE="0660"
     SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio",MODE="0660"
     SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", RUN+="${pkgs.bash}/bin/bash -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
     SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", RUN+="${pkgs.bash}/bin/bash -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
     SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",RUN+="${pkgs.bash}/bin/bash -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
     SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",RUN+="${pkgs.bash}/bin/bash -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
   '';
   '';
Line 197: Line 196:
</syntaxHighlight>
</syntaxHighlight>


The the <code>spi0-0cd.dtso</code> file can be downlaoded [https://github.com/raspberrypi/firmware/blob/master/boot/overlays/spi0-0cs.dtbo here].
The the <code>spi0-0cd.dtso</code> file can be downloaded [https://github.com/raspberrypi/firmware/blob/master/boot/overlays/spi0-0cs.dtbo here].
You might have to change the <code>compatible</code> field to "raspberrypi" in the dtbo file.
You might have to change the <code>compatible</code> field to "raspberrypi" in the dtbo file.


Line 271: Line 270:
=== Audio not playing and Bluetooth: no controller available ===
=== Audio not playing and Bluetooth: no controller available ===


On the Raspberry Pi kernel, the jack may never play audio, and no Bluetooth devices may ever be found. To get this to work, it is recommended to switch to the mainline kernel. See [https://github.com/NixOS/nixpkgs/issues/123725 nixpkgs#123725] for more info.
On the Raspberry Pi kernel, the jack may never play audio, and no Bluetooth devices may ever be found. To get this to work, it is recommended to switch to the mainline kernel. See [https://github.com/NixOS/nixpkgs/issues/123725 nixpkgs#123725] for more info.
 
<hr />
Anonymous user