ctucx.git: nixfiles

ctucx' nixfiles

commit b095220581776b0726817102e0f84c8743fabe2a
parent 230da64633e0cbadf2833f28c49c227278751e3f
Author: Leah (ctucx) <leah@ctu.cx>
Date: Wed, 12 Jan 2022 19:35:04 +0100

configurations/desktop-speakers: add helpers for my desktop speakers
1 file changed, 66 insertions(+), 0 deletions(-)
A
configurations/desktop-speakers.nix
|
66
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/configurations/desktop-speakers.nix b/configurations/desktop-speakers.nix
@@ -0,0 +1,66 @@
+{ config, pkgs, lib, ... }:
+
+{
+  services.physlock.enable       = lib.mkForce false;
+
+  home-manager.users.leah = {
+
+    wayland.windowManager.sway.config.keybindings = {
+      "${config.home-manager.users.leah.wayland.windowManager.sway.config.modifier}+Delete" = "exec curl -d '{\"accessToken\": \"penis123\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"toggle\": true}' http://10.0.0.1:5000";
+    };
+
+    systemd.user.services = {
+      speakers = {
+        Unit = {
+          Requisite = [ "graphical-session.target" ];
+
+          After     = [ "network-online.target" ];
+          Wants     = [ "network-online.target" ];
+        };
+
+        Service = {
+          RemainAfterExit = "yes";
+
+          ExecStartPre    = "/usr/bin/env sh -c 'until ping -c1 10.0.0.1; do sleep 0.1; done;'";
+          ExecStart       = "${pkgs.curl}/bin/curl -d '{\"accessToken\": \"penis123\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"state\": true}' http://10.0.0.1:5000";
+
+          ExecStopPre     = "/usr/bin/env sh -c 'until ping -c1 10.0.0.1; do sleep 0.1; done;'";
+          ExecStop        = "${pkgs.curl}/bin/curl -d '{\"accessToken\": \"penis123\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"state\": false}' http://10.0.0.1:5000";
+        };
+
+        Install = {
+          WantedBy  = [ "graphical-session.target" ];
+		};
+      };
+      speakers-lock = {
+        Unit = {
+          Requisite = [ "graphical-session.target" ];
+          PartOf    = [ "lock.target" "sleep.target" ];
+        };
+
+        Service = {
+          ExecStart = "${pkgs.systemd}/bin/systemctl --user stop speakers";
+        };
+
+        Install = {
+          WantedBy = [ "lock.target" "sleep.target" ];
+        };
+      };
+      speakers-unlock = {
+        Unit = {
+          Requisite = [ "graphical-session.target" ];
+          PartOf    = [ "unlock.target" ];
+        };
+
+        Service = {
+          ExecStart = "${pkgs.systemd}/bin/systemctl --user start speakers";
+        };
+
+        Install = {
+          WantedBy = [ "unlock.target" ];
+        };
+      };
+    };
+
+  };
+}