Created
August 16, 2021 16:26
-
-
Save MalteT/0e468f776b2063941969cea32c71420d to your computer and use it in GitHub Desktop.
Nixos module to add custom udev rules more easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # [ ... ] | |
| nixosModules.udevRule = { pkgs, lib, config, ... }: | |
| let | |
| createUdevPkg = { name, rules }: | |
| pkgs.writeTextFile { | |
| name = "custom-udev-rule-" + name; | |
| text = rules; | |
| destination = "/lib/udev/rules.d/" + name + ".rules"; | |
| }; | |
| cfg = config.services.udev.customRules; | |
| in { | |
| options = { | |
| services.udev.customRules = lib.mkOption { | |
| type = lib.types.listOf (lib.types.submodule { | |
| options = { | |
| name = lib.mkOption { | |
| type = lib.types.str; | |
| default = "99-custom.rules"; | |
| description = "The name of the file"; | |
| }; | |
| rules = lib.mkOption { | |
| type = lib.types.lines; | |
| description = "Content of the .rules"; | |
| }; | |
| }; | |
| }); | |
| default = [ ]; | |
| example = [{ | |
| name = "85-yubikey"; | |
| rules = '' | |
| SUBSYSTEM=="usb", ENV{ID_MODEL_ID}=="0407", ENV{ID_VENDOR_ID}=="1050", TAG+="systemd", SYMLINK+="yubikey" | |
| ''; | |
| }]; | |
| description = '' | |
| Additional custom udev rules | |
| ''; | |
| }; | |
| }; | |
| config = { services.udev.packages = map createUdevPkg cfg; }; | |
| }; | |
| # [ ... ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment