summary refs log tree commit diff
path: root/upstart-jobs/acpid.nix
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2009-02-22 16:08:28 +0000
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2009-02-22 16:08:28 +0000
commitbe4a0494b827affffeccef2462ae55d85e2f5dc8 (patch)
tree41cf55c2741fd9a47ecd353e7131a93681ce1ba9 /upstart-jobs/acpid.nix
parent128699688a1fb6812d9a22c7f9f95902a8e03d1d (diff)
downloadnixpkgs-be4a0494b827affffeccef2462ae55d85e2f5dc8.tar
nixpkgs-be4a0494b827affffeccef2462ae55d85e2f5dc8.tar.gz
nixpkgs-be4a0494b827affffeccef2462ae55d85e2f5dc8.tar.bz2
nixpkgs-be4a0494b827affffeccef2462ae55d85e2f5dc8.tar.lz
nixpkgs-be4a0494b827affffeccef2462ae55d85e2f5dc8.tar.xz
nixpkgs-be4a0494b827affffeccef2462ae55d85e2f5dc8.tar.zst
nixpkgs-be4a0494b827affffeccef2462ae55d85e2f5dc8.zip
* Suspend when the laptop lid is closed.
svn path=/nixos/branches/fix-style/; revision=14181
Diffstat (limited to 'upstart-jobs/acpid.nix')
-rw-r--r--upstart-jobs/acpid.nix19
1 files changed, 19 insertions, 0 deletions
diff --git a/upstart-jobs/acpid.nix b/upstart-jobs/acpid.nix
index 5bd1fa63590..efd608e1353 100644
--- a/upstart-jobs/acpid.nix
+++ b/upstart-jobs/acpid.nix
@@ -12,6 +12,9 @@ let
     ''
       event=button/power.*
       action=${powerEventHandler} "%e"
+
+      event=button/lid.*
+      action=${lidEventHandler} "%e"
     '';
 
   # Called when the power button is pressed.
@@ -23,6 +26,22 @@ let
       exit 0
     '';
 
+  # Called when the laptop lid is opened/closed.
+  lidEventHandler = pkgs.writeScript "acpi-lid.sh"
+    ''
+      #! ${pkgs.bash}/bin/sh
+
+      # Suspend to RAM if the lid is closed.  (We also get this event
+      # when the lid just opened, in which case we obviously don't
+      # want to suspend again.) 
+      if grep -q closed /proc/acpi/button/lid/LID/state; then
+          sync
+          echo mem > /sys/power/state
+      fi
+
+      exit 0
+    '';
+
 in
 
 {