summaryrefslogtreecommitdiff
path: root/nixos
diff options
context:
space:
mode:
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/catbus-actuator-wakeonlan.nix81
2 files changed, 82 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 5eb74ed..4f8e072 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -4,6 +4,7 @@
./hardware/yubikey.nix
./overlays.nix
./programs/dwm.nix
+ ./services/catbus-actuator-wakeonlan.nix
./services/catbus-bridge-snapcast.nix
./services/dlnatoad.nix
./services/helix-directory-jackalope.nix
diff --git a/nixos/modules/services/catbus-actuator-wakeonlan.nix b/nixos/modules/services/catbus-actuator-wakeonlan.nix
new file mode 100644
index 0000000..0187706
--- /dev/null
+++ b/nixos/modules/services/catbus-actuator-wakeonlan.nix
@@ -0,0 +1,81 @@
+{ config, lib, pkgs, ... }:
+with lib;
+
+let
+
+ cfg = config.eth.services.catbus-actuator-wakeonlan;
+
+ configJSON = pkgs.writeText "config.json" ''
+ {
+ "mqttBroker": "tcp://${cfg.mqttBroker.host}:${toString cfg.mqttBroker.port}",
+
+ "devices": {
+ "TV": {
+ "mac": "${cfg.devices.tv.mac}",
+ "topic": "${cfg.devices.tv.topic}"
+ }
+ }
+ }
+ '';
+
+in {
+
+ options.eth.services.catbus-actuator-wakeonlan = {
+
+ enable = mkEnableOption "Whether to enable the Catbus Wake-On-LAN actuator";
+
+ mqttBroker = {
+ host = mkOption {
+ type = types.str;
+ description = "Host of the MQTT broker.";
+ example = "localhost";
+ };
+ port = mkOption {
+ type = types.int;
+ description = "Port of the MQTT broker.";
+ default = 1883;
+ };
+ };
+
+ # TODO: replace this with a proper set of option sets.
+ devices = {
+ tv = {
+ mac = mkOption {
+ type = types.str;
+ description = "The device's MAC address";
+ example = "aa:bb:cc:dd:ee:ff";
+ };
+ topic = mkOption {
+ type = types.str;
+ description = "MQTT topic for controlling the device";
+ example = "home/house/speakers/power";
+ };
+ };
+ };
+ };
+
+
+ config = mkIf cfg.enable {
+ systemd.services.catbus-actuator-wakeonlan = {
+ enable = true;
+ description = "Power devices on using Wake-On-LAN via Catbus";
+ wants = [ "network.target" ];
+ after = [ "network.target" ];
+ wantedBy = [ "multi-user.target" ];
+ serviceConfig = {
+ DynamicUser = true;
+
+ ExecStart = "${pkgs.eth.catbus-wakeonlan}/bin/catbus-actuator-wakeonlan --config-path ${configJSON}";
+
+ NoNewPrivileges = true;
+ ProtectKernelTunables = true;
+ ProtectControlGroups = true;
+ ProtectKernelModules = true;
+ RestrictAddressFamilies = "AF_INET AF_INET6";
+ RestrictNamespaces = true;
+ };
+ };
+ };
+
+}
+