diff options
author | Ethel Morgan <eth@ethulhu.co.uk> | 2020-06-20 00:34:24 +0100 |
---|---|---|
committer | Ethel Morgan <eth@ethulhu.co.uk> | 2020-06-20 00:34:24 +0100 |
commit | c9aa5411bae3094eea433e0a975db0eb0ce27ef7 (patch) | |
tree | 33b37870fddc94e1cd043af12847f999d594b4c8 /nixos/modules | |
parent | 9a99413994d3468f65bc60f954046d6da2dfd80f (diff) |
add a barebones service config for catbus-actuator-wakeonlan
Diffstat (limited to '')
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/catbus-actuator-wakeonlan.nix | 81 |
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; + }; + }; + }; + +} + |