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>}}


=== Gpio ===
=== Using GPIO pins as non root ===
Add gpio group and change permission for all users in new gpio group.
Now all users in gpio group have access to /dev/gpiomem and to gpio pins via sysfs.


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.


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
The following code adds a group <code>gpio</code> and adds the user <code>mygpiouser</code> to that group.
   # add gpio 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 = {};


   # udev rule for 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 with gpio group
   # Add user to group
   users = {
   users = {
    mutableUsers = false;
     users.mygpiouser = {
     users.mygpiouser = {
      isNormalUser = true;
       extraGroups = [ "gpio" ... ];
      password = "mygpiouserpasswd";
      ....
       extraGroups = [ "wheel" "gpio" ];
     };
     };
   };
   };
 
</syntaxHighlight>
</nowiki>}}


=== HDMI-CEC ===
=== HDMI-CEC ===