How to create files in the `/etc/udev/rules.d/` directory?

hardware.keyboard.zsa.enable does not just work for me with a Moonlander keyboard. I had to look up the idVendor and idProduct using lsusb and udevadm (as described here). Then put this in my config:

services.udev.packages = [
      (pkgs.writeTextFile {
        name = "moonlander_udev";
        text = ''
          SUBSYSTEMS=="usb", ATTRS{idVendor}=="3297", ATTRS{idProduct}=="1969", MODE="0666", TAG+="uaccess", SYMLINK+="stm32_dfu", GROUP="plugdev"
        '';
        destination = "/etc/udev/rules.d/50-zsa.rules";
      })
    ];

I also had to create the plugdev group and add myself to it:

  users.groups.plugdev = {};
  users.users.felix = {
    extraGroups = [ "wheel" "foo" "bar" "plugdev"];
  };

After that, everything works like a charm. I’m not a Linux power user, much less a NixOS wizard. Just putting this here in case anyone else lands on this page while trying to get Oryx Live Training working on NixOS. (I don’t care about flashing for now, and am not sure whether this is sufficient.)

I’m not sure if the zsa-udev-rules package should be updated. I assume there might be a difference between different Moonlander generations? If more knowledgeable people chime in here, maybe we can make the ZSA keyboard experience on NixOS better! Seems to me there might be a relevant overlap between Moonlander users and NixOS users :slight_smile:

2 Likes