2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-02-22 16:08:22 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with 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
|
|
|
${
|
2012-12-15 11:31:32 +00:00
|
|
|
# Generate a configuration file for each event. (You can't have
|
2009-02-22 16:08:37 +00:00
|
|
|
# multiple events in one config file...)
|
|
|
|
let f = event:
|
|
|
|
''
|
2012-12-15 11:31:32 +00:00
|
|
|
fn=$out/${event.name}
|
2009-02-22 16:08:37 +00:00
|
|
|
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
|
|
|
'';
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
events = [powerEvent lidEvent acEvent];
|
2011-09-14 19:20:50 +01:00
|
|
|
|
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.*";
|
2011-09-14 19:20:50 +01:00
|
|
|
action =
|
2009-02-22 16:08:37 +00:00
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2010-04-08 16:27:20 +01:00
|
|
|
${config.services.acpid.powerEventCommands}
|
2009-02-22 16:08:37 +00:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-02-22 16:08:28 +00:00
|
|
|
# Called when the laptop lid is opened/closed.
|
2011-09-14 19:20:50 +01:00
|
|
|
lidEvent =
|
2009-02-22 16:08:37 +00:00
|
|
|
{ name = "lid";
|
|
|
|
event = "button/lid.*";
|
|
|
|
action =
|
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2010-04-08 16:27:20 +01:00
|
|
|
${config.services.acpid.lidEventCommands}
|
2009-02-22 16:08:37 +00:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 19:20:50 +01: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.*";
|
2011-09-14 19:20:50 +01:00
|
|
|
action =
|
2009-02-22 16:08:37 +00:00
|
|
|
''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
2010-04-08 16:27:20 +01:00
|
|
|
${config.services.acpid.acEventCommands}
|
2009-02-22 16:08:37 +00:00
|
|
|
'';
|
|
|
|
};
|
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 = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-11-15 12:48:42 +00:00
|
|
|
services.acpid = {
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2009-09-29 10:52:25 +01:00
|
|
|
default = false;
|
2009-11-15 12:48:42 +00:00
|
|
|
description = "Whether to enable the ACPI daemon.";
|
2009-09-29 10:52:25 +01:00
|
|
|
};
|
2010-04-08 16:27:20 +01:00
|
|
|
|
|
|
|
powerEventCommands = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.lines;
|
2010-04-08 16:27:20 +01:00
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on a button/power.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
lidEventCommands = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.lines;
|
2010-04-08 16:27:20 +01:00
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on a button/lid.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
acEventCommands = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.lines;
|
2010-04-08 16:27:20 +01:00
|
|
|
default = "";
|
2013-08-10 22:07:13 +01:00
|
|
|
description = "Shell commands to execute on an ac_adapter.* event.";
|
2010-04-08 16:27:20 +01:00
|
|
|
};
|
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-09-29 10:52:25 +01:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2009-11-15 12:48:42 +00:00
|
|
|
config = mkIf config.services.acpid.enable {
|
2009-03-06 12:25:25 +00:00
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.acpid =
|
2012-08-17 16:00:33 +01:00
|
|
|
{ description = "ACPI Daemon";
|
2009-09-29 10:52:25 +01:00
|
|
|
|
2012-08-17 16:00:33 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "systemd-udev-settle.service" ];
|
2009-09-29 10:52:25 +01:00
|
|
|
|
2011-11-25 16:32:54 +00:00
|
|
|
path = [ pkgs.acpid ];
|
|
|
|
|
|
|
|
daemonType = "fork";
|
|
|
|
|
|
|
|
exec = "acpid --confdir ${acpiConfDir}";
|
2012-10-05 04:26:01 +01:00
|
|
|
|
2013-11-26 17:17:12 +00:00
|
|
|
unitConfig.ConditionVirtualization = "!systemd-nspawn";
|
2012-10-05 04:26:01 +01:00
|
|
|
unitConfig.ConditionPathExists = [ "/proc/acpi" ];
|
2009-09-29 10:52:25 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-03-06 12:25:25 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-02-22 16:08:22 +00:00
|
|
|
}
|