about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/hardware/uni-sync.nix
blob: dd230ae419a1555b222110c4cc29080d5e3a3d6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{ config
, lib
, pkgs
, ...
}:
with lib; let
  cfg = config.hardware.uni-sync;
in
{
  meta.maintainers = with maintainers; [ yunfachi ];

  options.hardware.uni-sync = {
    enable = mkEnableOption "udev rules and software for Lian Li Uni Controllers";
    package = mkPackageOption pkgs "uni-sync" { };

    devices = mkOption {
      default = [ ];
      example = literalExpression ''
        [
          {
            device_id = "VID:1111/PID:11111/SN:1111111111";
            sync_rgb = true;
            channels = [
              {
                mode = "PWM";
              }
              {
                mode = "Manual";
                speed = 100;
              }
              {
                mode = "Manual";
                speed = 54;
              }
              {
                mode = "Manual";
                speed = 0;
              }
            ];
          }
          {
            device_id = "VID:1010/PID:10101/SN:1010101010";
            sync_rgb = false;
            channels = [
              {
                mode = "Manual";
                speed = 0;
              }
            ];
          }
        ]
      '';
      description = "List of controllers with their configurations.";
      type = types.listOf (types.submodule {
        options = {
          device_id = mkOption {
            type = types.str;
            example = "VID:1111/PID:11111/SN:1111111111";
            description = "Unique device ID displayed at each startup.";
          };
          sync_rgb = mkOption {
            type = types.bool;
            default = false;
            example = true;
            description = "Enable ARGB header sync.";
          };
          channels = mkOption {
            default = [ ];
            example = literalExpression ''
              [
                {
                  mode = "PWM";
                }
                {
                  mode = "Manual";
                  speed = 100;
                }
                {
                  mode = "Manual";
                  speed = 54;
                }
                {
                  mode = "Manual";
                  speed = 0;
                }
              ]
            '';
            description = "List of channels connected to the controller.";
            type = types.listOf (types.submodule {
              options = {
                mode = mkOption {
                  type = types.enum [ "Manual" "PWM" ];
                  default = "Manual";
                  example = "PWM";
                  description = "\"PWM\" to enable PWM sync. \"Manual\" to set speed.";
                };
                speed = mkOption {
                  type = types.int;
                  default = "50";
                  example = "100";
                  description = "Fan speed as percentage (clamped between 0 and 100).";
                };
              };
            });
          };
        };
      });
    };
  };

  config = mkIf cfg.enable {
    environment.etc."uni-sync/uni-sync.json".text = mkIf (cfg.devices != [ ]) (builtins.toJSON { configs = cfg.devices; });

    environment.systemPackages = [ cfg.package ];
    services.udev.packages = [ cfg.package ];
  };
}