From 0f88434da3a1e25c7280187a8cc7fc419cf048ea Mon Sep 17 00:00:00 2001 From: Sebastian Schulze Date: Thu, 20 Oct 2022 10:54:08 +0200 Subject: [PATCH] [nix] Add helper script to suspend only if it's the side computer --- bin/executable_suspend-if-docked | 10 ++++++++++ dot_config/nixpkgs/home.nix | 1 + 2 files changed, 11 insertions(+) create mode 100644 bin/executable_suspend-if-docked diff --git a/bin/executable_suspend-if-docked b/bin/executable_suspend-if-docked new file mode 100644 index 0000000..89000f1 --- /dev/null +++ b/bin/executable_suspend-if-docked @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +SWAYSOCK=/run/user/$(id -u)/sway-ipc.sock +DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus" +export SWAYSOCK +export DBUS_SESSION_BUS_ADDRESS + +if swaymsg -t get_inputs | grep "Planck EZ"; then + doas /run/current-system/sw/bin/systemctl suspend; +fi; diff --git a/dot_config/nixpkgs/home.nix b/dot_config/nixpkgs/home.nix index 6c8b529..b7dc2af 100644 --- a/dot_config/nixpkgs/home.nix +++ b/dot_config/nixpkgs/home.nix @@ -416,6 +416,7 @@ in unlock '${config.home.homeDirectory}/bin/thinkpad-dock' \ timeout 300 '${config.home.homeDirectory}/bin/blur-lock' \ timeout 600 '${pkgs.sway}/bin/swaymsg "output * dpms off"' \ + timeout 900 '${config.home.homeDirectory}/bin/suspend-if-docked' \ resume '${pkgs.sway}/bin/swaymsg "output * dpms on"' ''; Restart = "on-failure";