2009-02-11 00:25:49 +01:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
acpiConfDir = pkgs.runCommand "acpi-events" {}
|
|
|
|
''
|
|
|
|
ensureDir $out
|
2009-02-13 19:55:38 +01:00
|
|
|
${
|
|
|
|
# Generate a .conf file for each event. (You can't have
|
|
|
|
# multiple events in one config file...)
|
|
|
|
let f = event:
|
|
|
|
''
|
|
|
|
fn=$out/${event.name}.conf
|
|
|
|
echo "event=${event.event}" > $fn
|
|
|
|
echo "action=${pkgs.writeScript "${event.name}.sh" event.action}" >> $fn
|
|
|
|
'';
|
|
|
|
in pkgs.lib.concatMapStrings f events
|
|
|
|
}
|
2009-02-11 00:25:49 +01:00
|
|
|
'';
|
|
|
|
|
2009-02-13 19:55:38 +01:00
|
|
|
events = [powerEvent lidEvent acEvent];
|
2009-02-11 00:25:49 +01:00
|
|
|
|
|
|
|
# Called when the power button is pressed.
|
2009-02-13 19:55:38 +01:00
|
|
|
powerEvent =
|
|
|
|
{ name = "power-button";
|
|
|
|
event = "button/power.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
'';
|
|
|
|
};
|
2009-02-11 00:25:49 +01:00
|
|
|
|
2009-02-12 00:15:07 +01:00
|
|
|
# Called when the laptop lid is opened/closed.
|
2009-02-13 19:55:38 +01:00
|
|
|
lidEvent =
|
|
|
|
{ name = "lid";
|
|
|
|
event = "button/lid.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2009-02-12 00:15:07 +01:00
|
|
|
|
2009-02-13 19:55:38 +01:00
|
|
|
# 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
|
|
|
|
'';
|
|
|
|
};
|
2009-02-13 13:11:42 +01:00
|
|
|
|
|
|
|
# Called when the AC power is connected or disconnected.
|
2009-02-13 19:55:38 +01:00
|
|
|
acEvent =
|
|
|
|
{ name = "ac-power";
|
|
|
|
event = "ac_adapter.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2009-02-12 00:15:07 +01:00
|
|
|
|
2009-02-13 19:55:38 +01:00
|
|
|
if grep -q "state:.*on-line" /proc/acpi/ac_adapter/AC/state; then
|
|
|
|
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
|
|
|
|
elif grep -q "state:.*off-line" /proc/acpi/ac_adapter/AC/state; then
|
|
|
|
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2009-02-12 00:15:07 +01:00
|
|
|
|
2009-02-11 00:25:49 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
name = "acpid";
|
|
|
|
|
|
|
|
extraPath = [pkgs.acpid];
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
description "ACPI daemon"
|
|
|
|
|
|
|
|
start on udev
|
|
|
|
stop on shutdown
|
|
|
|
|
|
|
|
respawn ${pkgs.acpid}/sbin/acpid --foreground --confdir ${acpiConfDir}
|
|
|
|
'';
|
|
|
|
|
|
|
|
}
|