Add an udev rules.d file in a flake

I have a rules.d file containing a lot of rules (custom harddrive paths for many drives). For that reason I’d like to know how to add a file to /etc/udev/rules.d, rather than a few custom rule lines. I am using @Misterio’s nix-starter-configs flake, and my guess is that I need to create a custom pkg that adds my file to the pkgdir/etc/udev/rules.d/ directory, and add the name of that package to services.udev.packages. I haven’t created a custom pkg before, so I’d like to learn how to do that, if it is the correct approach. Do I add something to pkgs/default.nix?

Please and thank you.

Any takers? I could really use some help. :grimacing:


You probably don’t need a package for that. Usually services.udev.packages is more geared towards upstream packages that might provide rules you want to include. For your case, I’d simply do it like this:

  services.udev.extraRules = builtins.readFile ./rules-file;
1 Like

This worked great. Much thanks :hugs:

1 Like

Writing udev needs root permission, right? At what stage are the udev rules installed, build, install, or neither? How to give nix command the proper permission so that it can write udev rules specified by the flake?