summaryrefslogtreecommitdiff
path: root/nixos/modules/services/catbus-snapcast.nix
diff options
context:
space:
mode:
authorEthel Morgan <eth@ethulhu.co.uk>2020-06-29 23:10:16 +0100
committerEthel Morgan <eth@ethulhu.co.uk>2020-06-29 23:10:16 +0100
commit3683f93300c28011c81a5849132a54774d69ad2f (patch)
tree20c59463094cebdf57132d7fda0fbcbf802034b6 /nixos/modules/services/catbus-snapcast.nix
parent031b9e1b0cada730333e9dd1d0eb26cc975630f5 (diff)
refactor eth.services.catbus-snapcast
Diffstat (limited to '')
-rw-r--r--nixos/modules/services/catbus-snapcast.nix67
1 files changed, 67 insertions, 0 deletions
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;
+ };
+ };
+ };
+
+}
+