at 25.11-pre 1.1 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.hardware.i2c; 9in 10 11{ 12 options.hardware.i2c = { 13 enable = lib.mkEnableOption '' 14 i2c devices support. By default access is granted to users in the "i2c" 15 group (will be created if non-existent) and any user with a seat, meaning 16 logged on the computer locally 17 ''; 18 19 group = lib.mkOption { 20 type = lib.types.str; 21 default = "i2c"; 22 description = '' 23 Grant access to i2c devices (/dev/i2c-*) to users in this group. 24 ''; 25 }; 26 }; 27 28 config = lib.mkIf cfg.enable { 29 30 boot.kernelModules = [ "i2c-dev" ]; 31 32 users.groups = lib.mkIf (cfg.group == "i2c") { 33 i2c = { }; 34 }; 35 36 services.udev.packages = lib.singleton ( 37 pkgs.writeTextFile { 38 name = "i2c-udev-rules"; 39 text = '' 40 # allow group ${cfg.group} and users with a seat use of i2c devices 41 ACTION=="add", KERNEL=="i2c-[0-9]*", TAG+="uaccess", GROUP="${cfg.group}", MODE="660" 42 ''; 43 destination = "/etc/udev/rules.d/70-i2c.rules"; 44 } 45 ); 46 47 }; 48 49 meta.maintainers = [ lib.maintainers.rnhmjoj ]; 50 51}