blob: a46e31264e1e73831b4f9a21dc8bb9206eb0da48 (
plain)
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
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.eth.services.catbus-lifx;
configJSON = pkgs.writeText "config.json" (builtins.toJSON {
mqttBroker = cfg.mqttBroker;
bulbs = cfg.bulbs;
});
in {
options.eth.services.catbus-lifx = {
enable = mkEnableOption "Whether to enable the Catbus Lifx bulb daemons.";
mqttBroker = mkOption {
type = types.str;
description = "URL of the MQTT broker.";
example = "tcp://broker.local:1883";
};
bulbs = mkOption {
type = types.attrsOf (types.submodule {
options = {
topics = {
power = mkOption {
type = types.str;
description = "MQTT topic for controlling the bulb's power";
example = "home/living-room/light/power";
};
hue = mkOption {
type = types.str;
description = "MQTT topic for controlling the bulb's hue";
example = "home/living-room/light/hue_degrees";
};
saturation = mkOption {
type = types.str;
description = "MQTT topic for controlling the bulb's saturation";
example = "home/living-room/light/saturation_percent";
};
brightness = mkOption {
type = types.str;
description = "MQTT topic for controlling the bulb's brightness";
example = "home/living-room/light/brightness_percent";
};
kelvin = mkOption {
type = types.str;
description = "MQTT topic for controlling the bulb's kelvin";
example = "home/living-room/light/kelvin";
};
};
};
});
example = { Bedroom = { topics = { power = "home/living-room/light/power"; }; }; };
description = "A set of devices and their MACs & controller topics.";
};
};
config = mkIf cfg.enable {
systemd.services.catbus-lifx-actuator = {
enable = true;
description = "Control Lifx bulbs via Catbus";
wants = [ "network.target" ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
ExecStart = "${pkgs.eth.catbus-lifx}/bin/catbus-lifx-actuator --config-path ${configJSON}";
NoNewPrivileges = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
ProtectKernelModules = true;
RestrictAddressFamilies = "AF_INET AF_INET6";
RestrictNamespaces = true;
};
};
systemd.services.catbus-lifx-observer = {
enable = true;
description = "Observe Lifx bulbs via Catbus";
wants = [ "network.target" ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
ExecStart = "${pkgs.eth.catbus-lifx}/bin/catbus-lifx-observer --config-path ${configJSON}";
NoNewPrivileges = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
ProtectKernelModules = true;
RestrictAddressFamilies = "AF_INET AF_INET6";
RestrictNamespaces = true;
};
};
};
}
|