hswaw/machines/sound: spejsiot-polycom service, use full pulseaudio

Change-Id: Ia41ff02bf217a7116b4be87450723a7bbd549c0b
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1909
Reviewed-by: informatic <informatic@hackerspace.pl>
diff --git a/hswaw/machines/sound.waw.hackerspace.pl/configuration.nix b/hswaw/machines/sound.waw.hackerspace.pl/configuration.nix
index 9ff26c9..dc77cd5 100644
--- a/hswaw/machines/sound.waw.hackerspace.pl/configuration.nix
+++ b/hswaw/machines/sound.waw.hackerspace.pl/configuration.nix
@@ -32,7 +32,8 @@
   imports =
     [
       ./hardware-configuration.nix
-			./spejsiot-api.nix
+      ./spejsiot-api.nix
+      ./polycom.nix
     ];
 
   boot.loader.systemd-boot.enable = true;
@@ -146,6 +147,9 @@
     systemWide = true;
     zeroconf.publish.enable = true;
 
+    # Force use pulseaudioFull to prevent rebuild due to zeroconf
+    package = pkgs.pulseaudioFull;
+
     tcp.enable = true;
     tcp.anonymousClients.allowAll = true;
   };
diff --git a/hswaw/machines/sound.waw.hackerspace.pl/polycom.nix b/hswaw/machines/sound.waw.hackerspace.pl/polycom.nix
new file mode 100644
index 0000000..5ac3ce6
--- /dev/null
+++ b/hswaw/machines/sound.waw.hackerspace.pl/polycom.nix
@@ -0,0 +1,51 @@
+{ pkgs, ... }:
+let
+  python = pkgs.python3.withPackages (pp: [ pp.paho-mqtt ]);
+  src = pkgs.fetchgit {
+    url = "https://code.hackerspace.pl/informatic/spejsiot-polycom";
+    rev = "b1d41a3473a49ac9ef5771c8e704f33181989d92";
+    hash = "sha256-JdjGo1lR9adtHgtZZgtTf9uOhMzc/3OvO2/r6R/QipE=";
+  };
+in {
+  # Expose serial USB-Serial adapter connected to Polycom EF2280 mixer on TCP
+  # port 10001
+  systemd.services.socat-polycom = {
+    description = "Expose USB-serial adapter for Polycom EF2280 over TCP 10001";
+    wantedBy = [ "multi-user.target" ];
+    after = [ "network.target" ];
+
+    serviceConfig = {
+      ExecStart = "${pkgs.socat}/bin/socat TCP4-LISTEN:10001,fork,reuseaddr /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0,b38400,nonblock,raw,echo=0";
+      DynamicUser = true;
+      SupplementaryGroups = "dialout";
+      Restart = "always";
+    };
+  };
+
+  systemd.services.spejsiot-polycom = {
+    description = "Polycom EF2280 MQTT control bridge";
+    wantedBy = [ "multi-user.target" ];
+    after = [ "network.target" ];
+
+    serviceConfig = {
+      ExecStart = "${python}/bin/python3 ${src}/vortexiot.py";
+      DynamicUser = true;
+      Restart = "always";
+    };
+
+    environment.CONFIG_PATH = pkgs.writeText "config.json" (builtins.toJSON {
+      mqtt = { host = "127.0.0.1"; };
+      control = { host = "127.0.0.1";  port = 10001; };
+      inputs = {
+        aux1 = [ "1" "2" ];
+        sound = [ "A" "B" ];
+        hdmi = [ "C" "D" ];
+      };
+      outputs = {
+        main = [ "1" "2" ];
+      };
+    });
+  };
+
+  networking.firewall.allowedTCPPorts = [ 10001 ];
+}