From 3683f93300c28011c81a5849132a54774d69ad2f Mon Sep 17 00:00:00 2001 From: Ethel Morgan Date: Mon, 29 Jun 2020 23:10:16 +0100 Subject: refactor eth.services.catbus-snapcast --- nixos/modules/services/catbus-snapcast.nix | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 nixos/modules/services/catbus-snapcast.nix (limited to 'nixos/modules/services/catbus-snapcast.nix') diff --git a/nixos/modules/services/catbus-snapcast.nix b/nixos/modules/services/catbus-snapcast.nix new file mode 100644 index 0000000..8ee8301 --- /dev/null +++ b/nixos/modules/services/catbus-snapcast.nix @@ -0,0 +1,67 @@ +{ config, lib, pkgs, ... }: +with lib; + +let + + cfg = config.eth.services.catbus-snapcast; + + configJSON = pkgs.writeText "config.json" (builtins.toJSON { + mqttBroker = cfg.mqttBroker; + topics = cfg.topics; + snapcast = cfg.snapcast; + }); + +in { + + options.eth.services.catbus-snapcast = { + + enable = mkEnableOption "Whether to enable the Catbus Snapcast bridge"; + + mqttBroker = mkOption { + type = types.str; + description = "URL of the MQTT broker."; + example = "tcp://broker.local:1883"; + }; + + topics = { + input = mkOption { + type = types.str; + description = "MQTT topic for controlling the Snapcast group input"; + example = "home/house/speakers/input_enum"; + }; + }; + + snapcast = { + groupId = mkOption { + type = types.str; + description = "The ID of the Snapcast group to control"; + example = "352aba34-0ba8-8a4e-9f46-cb634b1c800a"; + }; + }; + }; + + + config = mkIf cfg.enable { + systemd.services.catbus-snapcast-bridge = { + enable = true; + description = "Control Snapcast via Catbus"; + wants = [ "network.target" ]; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + DynamicUser = true; + + ExecStart = "${pkgs.eth.catbus-snapcast}/bin/catbus-bridge-snapcast --config-path ${configJSON}"; + + NoNewPrivileges = true; + ProtectKernelTunables = true; + ProtectControlGroups = true; + ProtectKernelModules = true; + RestrictAddressFamilies = "AF_INET AF_INET6"; + RestrictNamespaces = true; + }; + }; + }; + +} + -- cgit v1.2.3