diff --git a/upstart-jobs/acpid.nix b/upstart-jobs/acpid.nix index 5bd1fa635906..efd608e13537 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 { diff --git a/upstart-jobs/hal.nix b/upstart-jobs/hal.nix index 181341fdcf4c..969823410800 100644 --- a/upstart-jobs/hal.nix +++ b/upstart-jobs/hal.nix @@ -44,6 +44,8 @@ let job = '' description "HAL daemon" + # !!! TODO: make sure that HAL starts after acpid, + # otherwise hald-addon-acpi will grab /proc/acpi/event. start on dbus stop on shutdown