diff options
author | Linnnus <[email protected]> | 2024-11-16 12:46:23 +0100 |
---|---|---|
committer | Linnnus <[email protected]> | 2024-11-16 12:46:23 +0100 |
commit | a876fe32b44dac8d6db23e7cd6b6f96b75ba0bbb (patch) | |
tree | 0ae34a6a1d0007c263262d2d055c977f8d657c1f | |
parent | 1f7610974ed8bcd98a4c646039aad538d19b54a6 (diff) |
pkgs: Add disable-sleep
-rw-r--r-- | pkgs/default.nix | 2 | ||||
-rw-r--r-- | pkgs/disable-sleep/default.nix | 30 |
2 files changed, 32 insertions, 0 deletions
diff --git a/pkgs/default.nix b/pkgs/default.nix index c97f271..bc17038 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -25,6 +25,8 @@ pkgs: { human-sleep = pkgs.callPackage ./human-sleep {}; + disable-sleep = pkgs.callPackage ./disable-sleep {}; + # TODO: These should be contained in the 'vimPlugins' attrset. This turns out # to be non-trivial because this module is both consumed in a flake output # context and an overlay context. diff --git a/pkgs/disable-sleep/default.nix b/pkgs/disable-sleep/default.nix new file mode 100644 index 0000000..07c3bb8 --- /dev/null +++ b/pkgs/disable-sleep/default.nix @@ -0,0 +1,30 @@ +{ + writeShellApplication, + human-sleep, +}: +writeShellApplication { + name = "disable-sleep"; + + runtimeInputs = [human-sleep]; + + text = '' + set -ue + + if [ "$(id -u)" -ne 0 ]; then + echo "Acquiring root access..." + exec sudo "$0" "$@" + fi + + cleanup() { + echo "Re-enabling sleep..." + pmset -a disablesleep 0 + } + + echo "Disabling sleep..." + pmset -a disablesleep 1 + trap cleanup EXIT + + echo "Waiting..." + human-sleep "$@" + ''; +} |