summaryrefslogtreecommitdiff
path: root/nixos
diff options
context:
space:
mode:
authorEthel Morgan <eth@ethulhu.co.uk>2020-06-30 11:36:39 +0100
committerEthel Morgan <eth@ethulhu.co.uk>2020-06-30 11:36:39 +0100
commitd1534dbca7cb8b0418b1e33cb6337db5453c06da (patch)
treefb56772bfd6ae6d8700976b17c86c73e66529a55 /nixos
parent6f6eb2c66dc4eadd9280e892de508593d7ed35d3 (diff)
add eth.services.catbus-lifx
Diffstat (limited to '')
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/catbus-lifx.nix106
2 files changed, 107 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index d3952f1..001f376 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -6,6 +6,7 @@
./programs/dwm.nix
./services/ambience.nix
./services/catbus-lgtv.nix
+ ./services/catbus-lifx.nix
./services/catbus-networkpresence.nix
./services/catbus-snapcast.nix
./services/catbus-wakeonlan.nix
diff --git a/nixos/modules/services/catbus-lifx.nix b/nixos/modules/services/catbus-lifx.nix
new file mode 100644
index 0000000..a46e312
--- /dev/null
+++ b/nixos/modules/services/catbus-lifx.nix
@@ -0,0 +1,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;
+ };
+ };
+ };
+
+}
+