2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-02-22 17:08:22 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2009-03-06 13:25:25 +01:00
|
|
|
|
2009-02-22 17:08:22 +01:00
|
|
|
let
|
|
|
|
|
|
|
|
acpiConfDir = pkgs.runCommand "acpi-events" {}
|
|
|
|
''
|
2014-06-30 14:56:10 +02:00
|
|
|
mkdir -p $out
|
2009-02-22 17:08:37 +01:00
|
|
|
${
|
2012-12-15 12:31:32 +01:00
|
|
|
# Generate a configuration file for each event. (You can't have
|
2009-02-22 17:08:37 +01:00
|
|
|
# multiple events in one config file...)
|
|
|
|
let f = event:
|
|
|
|
''
|
2012-12-15 12:31:32 +01:00
|
|
|
fn=$out/${event.name}
|
2009-02-22 17:08:37 +01:00
|
|
|
echo "event=${event.event}" > $fn
|
|
|
|
echo "action=${pkgs.writeScript "${event.name}.sh" event.action}" >> $fn
|
|
|
|
'';
|
2014-05-05 20:58:51 +02:00
|
|
|
in lib.concatMapStrings f events
|
2009-02-22 17:08:37 +01:00
|
|
|
}
|
2009-02-22 17:08:22 +01:00
|
|
|
'';
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2016-01-17 13:04:54 +01:00
|
|
|
events = [powerEvent lidEvent acEvent muteEvent volumeDownEvent volumeUpEvent cdPlayEvent cdNextEvent cdPrevEvent];
|
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
|
|
|
|
2016-01-17 13:04:54 +01:00
|
|
|
muteEvent = {
|
|
|
|
name = "mute";
|
|
|
|
event = "button/mute.*";
|
|
|
|
action = ''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
${config.services.acpid.muteCommands}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
volumeDownEvent = {
|
|
|
|
name = "volume-down";
|
|
|
|
event = "button/volumedown.*";
|
|
|
|
action = ''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
${config.services.acpid.volumeDownEventCommands}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
volumeUpEvent = {
|
|
|
|
name = "volume-up";
|
|
|
|
event = "button/volumeup.*";
|
|
|
|
action = ''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
${config.services.acpid.volumeUpEventCommands}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cdPlayEvent = {
|
|
|
|
name = "cd-play";
|
|
|
|
event = "cd/play.*";
|
|
|
|
action = ''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
${config.services.acpid.cdPlayEventCommands}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cdNextEvent = {
|
|
|
|
name = "cd-next";
|
|
|
|
event = "cd/next.*";
|
|
|
|
action = ''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
${config.services.acpid.cdNextEventCommands}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cdPrevEvent = {
|
|
|
|
name = "cd-prev";
|
|
|
|
event = "cd/prev.*";
|
|
|
|
action = ''
|
|
|
|
#! ${pkgs.bash}/bin/sh
|
|
|
|
${config.services.acpid.cdPrevEventCommands}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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 {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.bool;
|
2009-09-29 11:52:25 +02:00
|
|
|
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 {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.lines;
|
2010-04-08 17:27:20 +02:00
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on a button/power.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
lidEventCommands = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.lines;
|
2010-04-08 17:27:20 +02:00
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on a button/lid.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
acEventCommands = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.lines;
|
2010-04-08 17:27:20 +02:00
|
|
|
default = "";
|
2013-08-10 23:07:13 +02:00
|
|
|
description = "Shell commands to execute on an ac_adapter.* event.";
|
2010-04-08 17:27:20 +02:00
|
|
|
};
|
|
|
|
|
2016-01-17 13:04:54 +01:00
|
|
|
muteCommands = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on an button/mute.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
volumeDownEventCommands = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on an button/volumedown.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
volumeUpEventCommands = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on an button/volumeup.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
cdPlayEventCommands = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on an cd/play.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
cdNextEventCommands = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on an cd/next.* event.";
|
|
|
|
};
|
|
|
|
|
|
|
|
cdPrevEventCommands = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Shell commands to execute on an cd/prev.* 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
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
systemd.services.acpid = {
|
|
|
|
description = "ACPI Daemon";
|
2009-09-29 11:52:25 +02:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "systemd-udev-settle.service" ];
|
2009-09-29 11:52:25 +02:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
path = [ pkgs.acpid ];
|
2011-11-25 17:32:54 +01:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
};
|
2012-10-05 05:26:01 +02:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
unitConfig = {
|
|
|
|
ConditionVirtualization = "!systemd-nspawn";
|
|
|
|
ConditionPathExists = [ "/proc/acpi" ];
|
2009-09-29 11:52:25 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
script = "acpid --confdir ${acpiConfDir}";
|
|
|
|
};
|
|
|
|
|
2009-03-06 13:25:25 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-02-22 17:08:22 +01:00
|
|
|
}
|