udev.extraRules with external script

I’m trying to run a script when a keyboard is plugged in. Here’s my approach

services.udev.extraRules = let kbd-udev = pkgs.stdenv.mkDerivation { ... }; in ''
    ACTION=="add", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="2013", RUN+="${kbd-udev}/bin/kbd_udev", OWNER="philipp"

Where the mkDerivation just copies a shell script into the nix store.

This fails because

/nix/store/cjwyci23qb2h6k5ppa9wm69mwy80zksq-pmi-kbd-udev/bin/kbd_udev is called in udev rules but not installed by udev

What does this error mean to prevent, and how to I do this “the right way”?

It fails this check because your script isn’t executable. You can easily write shell scripts into the nix store using pkgs.writeShellScript.

Thanks @j-piecuch, that worked!

Kind of a bad error message though.

I remember looking at the same error message and having a hard time figuring it out, so I’ve opened a PR to change the error message:


Excellent. I love how this is handled!

1 Like