Skip to content

Commit c7fefa3

Browse files
committed
nixos: add try to make gpio work on rpi
1 parent a57da11 commit c7fefa3

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

nixos/hosts/pi4b/configuration.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{ stateVersion, ... }:
1+
{ pkgs, stateVersion, ... }:
22
{
33
hardware = {
4+
enableAllFirmware = true;
45
bluetooth.enable = true;
56
bluetooth.powerOnBoot = true;
67
};
@@ -16,6 +17,11 @@
1617
];
1718
};
1819

20+
environment.systemPackages = with pkgs; [
21+
libraspberrypi
22+
raspberrypi-eeprom
23+
];
24+
1925
i18n.defaultLocale = "en_US.UTF-8";
2026
console = {
2127
keyMap = "us";

nixos/hosts/pi4b/fan-control.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
environment.systemPackages = with pkgs; [
44
haskellPackages.gpio
5+
libgpiod
56
libraspberrypi
67
];
78

nixos/hosts/pi4b/gpio.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{ pkgs, user, ... }:
2+
{
3+
# Create gpio group
4+
users.groups.gpio = { };
5+
6+
# Change permissions gpio devices
7+
services.udev.extraRules = ''
8+
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio",MODE="0660"
9+
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'"
10+
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'"
11+
'';
12+
13+
# Add user to group
14+
users = {
15+
users."${user}" = {
16+
extraGroups = [ "gpio" ];
17+
};
18+
};
19+
}

0 commit comments

Comments
 (0)