summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkgs/default.nix2
-rw-r--r--pkgs/disable-sleep/default.nix30
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 "$@"
+ '';
+}