Raspberry Pi4 GPIO Permissions

I would like to use my Raspberry Pi 4 for some GPIO hardware experiments. I am using the pigpio C library and have an otherwise well working NixOS installed on the Raspberry. Trying to execute any pigpio stuff fails with initPeripherals: mmap gpio failed (Operation not permitted). There was an issue with the pigpio library on 64 bit linux kernels (see here), but using a recent version and setting iomem=relaxed and strict-devmem=0 in cmdline.txt seems to do the trick for the people there. I have a configuration.nix with

  boot = {
    loader = {
      # Use the extlinux bootloader instead of Grub.
      grub.enable = false;
      generic-extlinux-compatible.enable = true;
      raspberryPi = {
        enable = true;
        version = 4;
        # Stuff that goes into /boot/config.txt
        firmwareConfig = ''

  boot.initrd.availableKernelModules = [ "usbhid" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ ];
  boot.extraModulePackages = [ ];

  fileSystems = {
    "/" = { 
      device = "/dev/disk/by-label/NIXOS_SD";
      fsType = "ext4";

but unfortunately firmwareConfig does not seem to help. Was anyone able to get the GPIO ports on the Raspberry Pi 4 working or could give me any hint how to solve this problem?

Best wishes

1 Like

Unfortunately I don’t have an answer, but I’m using the Adafruit_DHT Python package (which has been deprecated). I got it to work with a custom SD image based (using uboot) on an older nixpkgs commit. My setup since broke and I didn’t have the time to fix it.

FWIW, the official aarch64 image seems not to be enabling the GPIO interface at all. There is a way to make NixOS use uboot and the same boot mechanism as Raspbian, but I never understood it well enough and now it broke on me (after a recent upgrade to latest nixpkgs-unstable).

I should be able to find more time in the following months to experiment and hopefully together we can get something to work on RPi4. In any case, I suspect I’ll need quite a bit of help from anyone who knows anything at all about NixOS on RPi.

Edit: Oh my, missed an important “not”. Now added and highlighted in bold.


Nice to hear that you found an approach that is promising. :slightly_smiling_face: The GPIO seems to available to some extent by the standard kernel interface. But unfortunately this excludes things like I2P and hardware PWM. But liggpiod and other non-RPi specific libraries in principle seem to work.

Unfortunately this depth of kernel magic and booting is beyond my expertise, but I can try to help testing. :slightly_smiling_face:

I also have an issue open on nixpkgs, see here: Raspberry Pi4: GPIO Access and Hardware Revision Missing · Issue #122993 · NixOS/nixpkgs · GitHub