Add custom udev rule without using "99-local.rules"

As the title suggests, I need to create a custom udev rule, that doesn’t go into 99-local.rules.
This makes it impossible for me to use any of the available (from what I know) options provided by services.udev.*, such as .extraRules to create the rule.
While searching for the answer, I learned about tmpfiles, but when I tried using it to create a udev rule, nothing has been created. Maybe somewhere an error-log has been created, but I do not know where to even search for it.
The config that I used is:

  systemd.tmpfiles.settings = {
    "91-opentabletdrive-adds.rules" = {
      "/etc/udev/rules.d" = {
        f = {
          mode = "764";
          user = "mustlane";
          group = "wheel";
          type = "f";
          argument = ''
            KERNEL=="hidraw*", ATTRS{idVendor}=="256c", ATTRS{idProduct}=="0067", TAG+="uaccess", TAG+="udev-acl"\nSUBSYSTEM=="usb", ATTRS{idVendor}=="256c", ATTRS{idProduct}=="0067", TAG+="uaccess", TAG+="udev-a>
          '';
        };
      };
    };
  };

So, the question is:
Is there an option to create a custom udev rule, and if not, then is there any options to create the rule declaratively, other than (obviously) using bash scripting?
Thanks for help in advance!

1 Like

Use services.udev.packages. For example,

    services.udev.packages = lib.singleton (
      pkgs.writeTextFile {
        name = "i2c-udev-rules";
        text = ''
          # allow group ${cfg.group} and users with a seat use of i2c devices
          ACTION=="add", KERNEL=="i2c-[0-9]*", TAG+="uaccess", GROUP="${cfg.group}", MODE="660"
        '';
        destination = "/etc/udev/rules.d/70-i2c.rules";
      }
    );

2 Likes

E.g.:

{ pkgs, lib, ... }: {
  services.udev.packages = [
    (pkgs.writeTextFile {
      name = "91-opentabletdrive-adds.rules";
      text = ''
        KERNEL=="hidraw*", ATTRS{idVendor}=="256c", ATTRS{idProduct}=="0067", TAG+="uaccess", TAG+="udev-acl"
        SUBSYSTEM=="usb", ATTRS{idVendor}=="256c", ATTRS{idProduct}=="0067", TAG+="uaccess", TAG+="udev-acl"
      '';
      destination = "/lib/udev/rules.d/91-opentabletdrive-adds.rules";

      checkPhase = ''
        ${lib.getExe' pkgs.systemd "udevadm"} verify $out/lib/udev/rules.d/91-opentabletdrive-adds.rules
      '';
     })
  ];
}

There really should be an option to make this a bit easier, I’d like to add one sometime.

2 Likes

Hehe, didn’t see you replied before I hit the button.

It would be good to have a submodule like

services.udev.rules.<name>.text
services.udev.rules.<name>.priority
7 Likes