diff --git a/flake.nix b/flake.nix index 337b7a2..3a42732 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,7 @@ packages.showGokillStatus = let watchGokillStatus = pkgs.writeShellScriptBin "watch-gokill-status" '' - watch -c -t "${gokillPackage}/bin/gokillctl --db=/etc/gokill status; ${gokillPackage}/bin/gokillctl --db=/etc/gokill remote status" + ${pkgs.procps}/bin/watch -c -t "${gokillPackage}/bin/gokillctl --db=/etc/gokill status; ${gokillPackage}/bin/gokillctl --db=/etc/gokill remote status" ''; in pkgs.writeShellScriptBin "show-gokill-status" '' @@ -34,16 +34,64 @@ APP_COMMAND="${watchGokillStatus}/bin/watch-gokill-status" TARGET_WORKSPACE="1" - i3-msg "exec $TERMINAL -T 'Status' -e $APP_COMMAND;" - # workspace $TARGET_WORKSPACE; \ + #env DISPLAY=:0 ${pkgs.sudo}/bin/sudo su -c "${pkgs.i3}/bin/i3-msg \"exec $TERMINAL -T 'Status' -e $APP_COMMAND;\"" rpi + ${pkgs.i3}/bin/i3-msg "exec $TERMINAL -T 'Status' -e $APP_COMMAND"; # layout tabbed" ''; + packages.alarmSound = pkgs.writeShellScriptBin "alarm-sound" '' + # 533 == pin 21 + # use cat /sys/kernel/debug/gpio to get assignments + + exportPin() + { + if [ ! -e $BASE_GPIO_PATH/gpio$1 ]; then + echo "$1" > /sys/class/gpio/export + echo "out" > /sys/class/gpio/gpio$1/direction + fi + } + + setState() + { + echo $2 > /sys/class/gpio/gpio$1/value + } + + # GPIO 26 - Use as VCC + exportPin "538" + setState "538" "1" + + # GPIO 19 - Use as Signal + exportPin "531" + + echo "Starting Alert sound!" + for i in {1..5}; do + echo "Alert Iteration $i of 5" + setState "531" "1" + sleep 1 + setState "531" "0" + sleep 1 + done + echo "Finished Alert sound!" + ''; + + packages.showAlert = pkgs.writeShellScriptBin "show-alert" '' + echo "show alert" + export DISPLAY=:0 + echo "call xset" + ${pkgs.xorg.xset}/bin/xset dpms force on + echo "call alert" + ${self.packages.${system}.alertTest}/bin/alert + + #env DISPLAY=:0 sudo su -c "${pkgs.xorg.xset}/bin/xset dpms force on" rpi + #env DISPLAY=:0 sudo su -c "${self.packages.${system}.alertTest}/bin/alert" rpi + ''; + + packages.alertTest = pkgs.buildGoModule { pname = "alertTest"; version = "0.5"; vendorHash = "sha256-VNhegIXNH4rNdLaH8fALtA6iMu5ejX3gqXQRw9TWDU8="; - src = ./.; + src = ./scripts/alert; nativeBuildInputs = [ pkgs.pkg-config @@ -86,6 +134,7 @@ modules = [ "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" inputs.nixos-hardware.nixosModules.raspberry-pi-3 + inputs.gokill.nixosModules.gokill ({ pkgs, ... }: { nix.nixPath = [ @@ -202,7 +251,56 @@ ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot ''; }; - + + systemd.services.gokill-status = { + enable = true; + description = "Open gokill status view at boot"; + wantedBy = [ "graphical.target" ]; + environment = { + DISPLAY = ":0"; + XAUTHORITY = "/home/rpi/.Xauthority"; + }; + serviceConfig = { + ExecStart = "${self.packages.aarch64-linux.showGokillStatus}/bin/show-gokill-status"; + }; + }; + + systemd.services.gokill = { + environment = { + DISPLAY = ":0"; + XAUTHORITY = "/home/rpi/.Xauthority"; + }; + }; + + services.gokill = + { + enable = true; + triggers = [ + { + type = "Timeout"; + name = "custom timeout"; + options = { + duration = 60; + }; + actions = [ + { + type = "ShellScript"; + options = { + path = "${inputs.self.packages.aarch64-linux.showAlert}/bin/show-alert"; + }; + stage = 1; + } + #{ + # type = "ShellScript"; + # options = { + # path = "${self.packages.aarch64-linux.alarmSound}/bin/alarm-sound"; + # }; + # stage = 1; + #} + ]; + } + ]; + }; services.displayManager = { autoLogin.enable = true; diff --git a/alert.go b/scripts/alert/alert.go similarity index 100% rename from alert.go rename to scripts/alert/alert.go diff --git a/go.mod b/scripts/alert/go.mod similarity index 100% rename from go.mod rename to scripts/alert/go.mod diff --git a/go.sum b/scripts/alert/go.sum similarity index 100% rename from go.sum rename to scripts/alert/go.sum