2009-09-29 11:52:25 +02:00
|
|
|
{ config, pkgs, ... }:
|
2009-02-22 17:08:22 +01:00
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
with pkgs.lib;
|
2009-03-06 13:25:25 +01:00
|
|
|
|
2009-02-22 17:08:22 +01:00
|
|
|
let
|
|
|
|
|
|
|
|
acpiConfDir = pkgs.runCommand "acpi-events" {}
|
|
|
|
''
|
|
|
|
ensureDir $out
|
2009-02-22 17:08:37 +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-22 17:08:22 +01:00
|
|
|
'';
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
events = [powerEvent lidEvent acEvent];
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-02-22 17:08:22 +01:00
|
|
|
# Called when the power button is pressed.
|
2009-02-22 17:08:37 +01:00
|
|
|
powerEvent =
|
|
|
|
{ name = "power-button";
|
|
|
|
event = "button/power.*";
|
2011-09-14 20:20:50 +02:00
|
|
|
action =
|
2009-02-22 17:08:37 +01:00
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2010-04-08 17:27:20 +02:00
|
|
|
${config.services.acpid.powerEventCommands}
|
2009-02-22 17:08:37 +01:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-02-22 17:08:28 +01:00
|
|
|
# Called when the laptop lid is opened/closed.
|
2011-09-14 20:20:50 +02:00
|
|
|
lidEvent =
|
2009-02-22 17:08:37 +01:00
|
|
|
{ name = "lid";
|
|
|
|
event = "button/lid.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2010-04-08 17:27:20 +02:00
|
|
|
${config.services.acpid.lidEventCommands}
|
2009-02-22 17:08:37 +01:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-02-22 17:08:33 +01:00
|
|
|
# Called when the AC power is connected or disconnected.
|
2009-02-22 17:08:37 +01:00
|
|
|
acEvent =
|
|
|
|
{ name = "ac-power";
|
|
|
|
event = "ac_adapter.*";
|
2011-09-14 20:20:50 +02:00
|
|
|
action =
|
2009-02-22 17:08:37 +01:00
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2010-04-08 17:27:20 +02:00
|
|
|
${config.services.acpid.acEventCommands}
|
2009-02-22 17:08:37 +01:00
|
|
|
'';
|
|
|
|
};
|
2009-02-22 17:08:28 +01:00
|
|
|
|
2009-02-22 17:08:22 +01:00
|
|
|
in
|
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
{
|
2009-02-22 17:08:22 +01:00
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
###### interface
|
2009-02-22 17:08:22 +01:00
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-11-15 13:48:42 +01:00
|
|
|
services.acpid = {
|
2009-03-06 13:25:25 +01:00
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
2009-11-15 13:48:42 +01:00
|
|
|
description = "Whether to enable the ACPI daemon.";
|
2009-09-29 11:52:25 +02:00
|
|
|
};
|
2010-04-08 17:27:20 +02:00
|
|
|
|
|
|
|
powerEventCommands = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on a button/power.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
lidEventCommands = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on a button/lid.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
acEventCommands = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on a ac_adapter.* event.";
|
|
|
|
};
|
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-29 11:52:25 +02:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2009-11-15 13:48:42 +01:00
|
|
|
config = mkIf config.services.acpid.enable {
|
2009-03-06 13:25:25 +01:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.acpid =
|
2009-10-12 19:27:57 +02:00
|
|
|
{ description = "ACPI daemon";
|
2009-09-29 11:52:25 +02:00
|
|
|
|
2010-07-09 14:35:06 +02:00
|
|
|
startOn = "stopped udevtrigger and started syslogd";
|
2009-09-29 11:52:25 +02:00
|
|
|
|
|
|
|
exec = "${pkgs.acpid}/sbin/acpid --foreground --confdir ${acpiConfDir}";
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-03-06 13:25:25 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-02-22 17:08:22 +01:00
|
|
|
}
|