2009-09-29 10:52:25 +01:00
|
|
|
{ config, pkgs, ... }:
|
2009-02-22 16:08:22 +00:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
with pkgs.lib;
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-02-22 16:08:22 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
acpiConfDir = pkgs.runCommand "acpi-events" {}
|
|
|
|
''
|
|
|
|
ensureDir $out
|
2009-02-22 16:08:37 +00: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-22 16:08:22 +00:00
|
|
|
'';
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
events = [powerEvent lidEvent acEvent];
|
|
|
|
|
2009-02-22 16:08:22 +00:00
|
|
|
# Called when the power button is pressed.
|
2009-02-22 16:08:37 +00:00
|
|
|
powerEvent =
|
|
|
|
{ name = "power-button";
|
|
|
|
event = "button/power.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
'';
|
|
|
|
};
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-02-22 16:08:28 +00:00
|
|
|
# Called when the laptop lid is opened/closed.
|
2009-02-22 16:08:37 +00:00
|
|
|
lidEvent =
|
|
|
|
{ name = "lid";
|
|
|
|
event = "button/lid.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
'';
|
|
|
|
};
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-02-22 16:08:33 +00:00
|
|
|
# Called when the AC power is connected or disconnected.
|
2009-02-22 16:08:37 +00:00
|
|
|
acEvent =
|
|
|
|
{ name = "ac-power";
|
|
|
|
event = "ac_adapter.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
'';
|
|
|
|
};
|
2009-02-22 16:08:28 +00:00
|
|
|
|
2009-02-22 16:08:22 +00:00
|
|
|
in
|
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
{
|
2009-02-22 16:08:22 +00:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
###### interface
|
2009-02-22 16:08:22 +00:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
options = {
|
|
|
|
|
|
|
|
powerManagement = {
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable power management (ACPI daemon)";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.powerManagement.enable {
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
jobs = singleton
|
|
|
|
{ name = "acpid";
|
|
|
|
description = "ACPI daemon";
|
|
|
|
|
|
|
|
startOn = "udev";
|
|
|
|
stopOn = "shutdown";
|
|
|
|
|
|
|
|
exec = "${pkgs.acpid}/sbin/acpid --foreground --confdir ${acpiConfDir}";
|
|
|
|
};
|
|
|
|
|
2009-03-06 12:25:25 +00:00
|
|
|
};
|
2009-09-29 10:52:25 +01:00
|
|
|
|
2009-02-22 16:08:22 +00:00
|
|
|
}
|