NixOS on ARM/Raspberry Pi 4: Difference between revisions
imported>Valodim adapt hdmi-cec for nixos-22.11 |
imported>Jooooscha Add explaination on why applying the GPIO code works |
||
Line 180: | Line 180: | ||
</nowiki>}} | </nowiki>}} | ||
=== | === Using GPIO pins as non root === | ||
By default, the GPIO pins are enable, 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. | |||
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. | ||
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>. | |||
Therefore, the root user and anyone in the gpio group can now access the GPIO pins. | |||
<syntaxHighlight lang="nix"> | |||
# Create gpio group | |||
users.groups.gpio = {}; | users.groups.gpio = {}; | ||
# | # Change permissions gpio devices | ||
services.udev.extraRules = '' | services.udev.extraRules = '' | ||
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio",MODE="0660" | SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio",MODE="0660" | ||
Line 196: | Line 202: | ||
''; | ''; | ||
# | # Add user to group | ||
users = { | users = { | ||
users.mygpiouser = { | users.mygpiouser = { | ||
extraGroups = [ "gpio" ... ]; | |||
.... | |||
extraGroups = [ | |||
}; | }; | ||
}; | }; | ||
</syntaxHighlight> | |||
</ | |||
=== HDMI-CEC === | === HDMI-CEC === |