1{
2 pkgs,
3 lib,
4 config,
5 ...
6}:
7let
8 cfg = config.services.hardware.openrgb;
9in
10{
11 options.services.hardware.openrgb = {
12 enable = lib.mkEnableOption "OpenRGB server, for RGB lighting control";
13
14 package = lib.mkPackageOption pkgs "openrgb" { };
15
16 motherboard = lib.mkOption {
17 type = lib.types.nullOr (
18 lib.types.enum [
19 "amd"
20 "intel"
21 ]
22 );
23 default =
24 if config.hardware.cpu.intel.updateMicrocode then
25 "intel"
26 else if config.hardware.cpu.amd.updateMicrocode then
27 "amd"
28 else
29 null;
30 defaultText = lib.literalMD ''
31 if config.hardware.cpu.intel.updateMicrocode then "intel"
32 else if config.hardware.cpu.amd.updateMicrocode then "amd"
33 else null;
34 '';
35 description = "CPU family of motherboard. Allows for addition motherboard i2c support.";
36 };
37
38 server.port = lib.mkOption {
39 type = lib.types.port;
40 default = 6742;
41 description = "Set server port of openrgb.";
42 };
43
44 };
45
46 config = lib.mkIf cfg.enable {
47 environment.systemPackages = [ cfg.package ];
48 services.udev.packages = [ cfg.package ];
49
50 boot.kernelModules =
51 [ "i2c-dev" ]
52 ++ lib.optionals (cfg.motherboard == "amd") [ "i2c-piix4" ]
53 ++ lib.optionals (cfg.motherboard == "intel") [ "i2c-i801" ];
54
55 systemd.services.openrgb = {
56 description = "OpenRGB server daemon";
57 after = [ "network.target" ];
58 wants = [ "dev-usb.device" ];
59 wantedBy = [ "multi-user.target" ];
60 serviceConfig = {
61 StateDirectory = "OpenRGB";
62 WorkingDirectory = "/var/lib/OpenRGB";
63 ExecStart = "${cfg.package}/bin/openrgb --server --server-port ${toString cfg.server.port}";
64 Restart = "always";
65 };
66 };
67 };
68
69 meta.maintainers = [ ];
70}