ctucx.git: nixfiles

ctucx' nixfiles

commit 12cc13ffdf036611ee6db6233b5382608c66ab05
parent 8b069b9e827ea846f18206cf0acd56ce03a80aee
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sat, 2 Apr 2022 22:59:41 +0200

machines/blechbuechse: control desktop-speakers via key-combo and sleep-state of mac
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/machines/blechbuechse/darwin-configuration.nix b/machines/blechbuechse/darwin-configuration.nix
@@ -31,6 +31,7 @@ in {
     ./yabai.nix
     ./skhd.nix
     ./keyboard.nix
+    ./speakers.nix
   ];
 
   nix.package = pkgs.nix;
diff --git a/machines/blechbuechse/speakers.nix b/machines/blechbuechse/speakers.nix
@@ -0,0 +1,30 @@
+{ config, pkgs, lib, ... }:
+
+let
+  secrets        = import ../../secrets;
+  SpeakerDaemon  = pkgs.callPackage ../../pkgs/SpeakerDaemon {};
+  switchSpeakers = pkgs.writeScript "switchSpeakers.sh" ''
+    #!/usr/bin/env bash
+
+    curl -d '{"accessToken": "${secrets.hosts.lollo.smartied.accessToken}", "type": "SwitchStateAction", "deviceName": "modbus-20", "relay": 0, "toggle": true}' http://10.0.0.1:5000
+  '';
+
+in {
+
+  services.skhd = {
+    enable     = true;
+    skhdConfig = ''
+      # Switch speakers
+      lalt - delete : ${switchSpeakers}
+    '';
+  };
+
+  launchd.user.agents.SpeakerDaemon = {
+    path = [ config.environment.systemPath ];
+
+    serviceConfig = {
+      ProgramArguments = [ "${SpeakerDaemon}/bin/SpeakerDaemon" ];
+      KeepAlive        = true;
+    };
+  };
+}