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