* Generate the acpid configuration properly: each config file
can only contain one event. svn path=/nixos/trunk/; revision=14080
This commit is contained in:
parent
03e7f296b1
commit
4dacbc3c79
@ -5,54 +5,64 @@ let
|
||||
acpiConfDir = pkgs.runCommand "acpi-events" {}
|
||||
''
|
||||
ensureDir $out
|
||||
ln -s ${acpiConfFile} $out/events.conf
|
||||
${
|
||||
# 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
|
||||
}
|
||||
'';
|
||||
|
||||
acpiConfFile = pkgs.writeText "acpi.conf"
|
||||
''
|
||||
event=button/power.*
|
||||
action=${powerEventHandler} "%e"
|
||||
|
||||
event=button/lid.*
|
||||
action=${lidEventHandler} "%e"
|
||||
|
||||
event=ac_adapter.*
|
||||
action=${acEventHandler} "%e"
|
||||
'';
|
||||
events = [powerEvent lidEvent acEvent];
|
||||
|
||||
# Called when the power button is pressed.
|
||||
powerEventHandler = pkgs.writeScript "acpi-power.sh"
|
||||
''
|
||||
#! ${pkgs.bash}/bin/sh
|
||||
# Suspend to RAM.
|
||||
#echo mem > /sys/power/state
|
||||
'';
|
||||
powerEvent =
|
||||
{ name = "power-button";
|
||||
event = "button/power.*";
|
||||
action =
|
||||
''
|
||||
#! ${pkgs.bash}/bin/sh
|
||||
'';
|
||||
};
|
||||
|
||||
# Called when the laptop lid is opened/closed.
|
||||
lidEventHandler = pkgs.writeScript "acpi-lid.sh"
|
||||
''
|
||||
#! ${pkgs.bash}/bin/sh
|
||||
lidEvent =
|
||||
{ name = "lid";
|
||||
event = "button/lid.*";
|
||||
action =
|
||||
''
|
||||
#! ${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
|
||||
'';
|
||||
# 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
|
||||
'';
|
||||
};
|
||||
|
||||
# Called when the AC power is connected or disconnected.
|
||||
acEventHandler = pkgs.writeScript "ac-power.sh"
|
||||
''
|
||||
#! ${pkgs.bash}/bin/sh
|
||||
acEvent =
|
||||
{ name = "ac-power";
|
||||
event = "ac_adapter.*";
|
||||
action =
|
||||
''
|
||||
#! ${pkgs.bash}/bin/sh
|
||||
|
||||
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
|
||||
'';
|
||||
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
|
||||
'';
|
||||
};
|
||||
|
||||
in
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user