1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7with lib;
8let
9 cfg = config.hardware.uni-sync;
10in
11{
12 meta.maintainers = with maintainers; [ yunfachi ];
13
14 options.hardware.uni-sync = {
15 enable = mkEnableOption "udev rules and software for Lian Li Uni Controllers";
16 package = mkPackageOption pkgs "uni-sync" { };
17
18 devices = mkOption {
19 default = [ ];
20 example = literalExpression ''
21 [
22 {
23 device_id = "VID:1111/PID:11111/SN:1111111111";
24 sync_rgb = true;
25 channels = [
26 {
27 mode = "PWM";
28 }
29 {
30 mode = "Manual";
31 speed = 100;
32 }
33 {
34 mode = "Manual";
35 speed = 54;
36 }
37 {
38 mode = "Manual";
39 speed = 0;
40 }
41 ];
42 }
43 {
44 device_id = "VID:1010/PID:10101/SN:1010101010";
45 sync_rgb = false;
46 channels = [
47 {
48 mode = "Manual";
49 speed = 0;
50 }
51 ];
52 }
53 ]
54 '';
55 description = "List of controllers with their configurations.";
56 type = types.listOf (
57 types.submodule {
58 options = {
59 device_id = mkOption {
60 type = types.str;
61 example = "VID:1111/PID:11111/SN:1111111111";
62 description = "Unique device ID displayed at each startup.";
63 };
64 sync_rgb = mkOption {
65 type = types.bool;
66 default = false;
67 example = true;
68 description = "Enable ARGB header sync.";
69 };
70 channels = mkOption {
71 default = [ ];
72 example = literalExpression ''
73 [
74 {
75 mode = "PWM";
76 }
77 {
78 mode = "Manual";
79 speed = 100;
80 }
81 {
82 mode = "Manual";
83 speed = 54;
84 }
85 {
86 mode = "Manual";
87 speed = 0;
88 }
89 ]
90 '';
91 description = "List of channels connected to the controller.";
92 type = types.listOf (
93 types.submodule {
94 options = {
95 mode = mkOption {
96 type = types.enum [
97 "Manual"
98 "PWM"
99 ];
100 default = "Manual";
101 example = "PWM";
102 description = "\"PWM\" to enable PWM sync. \"Manual\" to set speed.";
103 };
104 speed = mkOption {
105 type = types.int;
106 default = "50";
107 example = "100";
108 description = "Fan speed as percentage (clamped between 0 and 100).";
109 };
110 };
111 }
112 );
113 };
114 };
115 }
116 );
117 };
118 };
119
120 config = mkIf cfg.enable {
121 environment.etc."uni-sync/uni-sync.json".text = mkIf (cfg.devices != [ ]) (
122 builtins.toJSON { configs = cfg.devices; }
123 );
124
125 environment.systemPackages = [ cfg.package ];
126 services.udev.packages = [ cfg.package ];
127 };
128}