···
7
-
acpiConfDir = pkgs.runCommand "acpi-events" {}
11
-
# Generate a configuration file for each event. (You can't have
12
-
# multiple events in one config file...)
15
-
fn=$out/${event.name}
16
-
echo "event=${event.event}" > $fn
17
-
echo "action=${pkgs.writeScript "${event.name}.sh" event.action}" >> $fn
19
-
in lib.concatMapStrings f events
23
-
events = [powerEvent lidEvent acEvent muteEvent volumeDownEvent volumeUpEvent cdPlayEvent cdNextEvent cdPrevEvent];
25
-
# Called when the power button is pressed.
27
-
{ name = "power-button";
7
+
canonicalHandlers = {
event = "button/power.*";
31
-
#! ${pkgs.bash}/bin/sh
32
-
${config.services.acpid.powerEventCommands}
10
+
action = config.services.acpid.powerEventCommands;
36
-
# Called when the laptop lid is opened/closed.
42
-
#! ${pkgs.bash}/bin/sh
43
-
${config.services.acpid.lidEventCommands}
15
+
action = config.services.acpid.lidEventCommands;
47
-
# Called when the AC power is connected or disconnected.
49
-
{ name = "ac-power";
53
-
#! ${pkgs.bash}/bin/sh
54
-
${config.services.acpid.acEventCommands}
20
+
action = config.services.acpid.acEventCommands;
60
-
event = "button/mute.*";
62
-
#! ${pkgs.bash}/bin/sh
63
-
${config.services.acpid.muteCommands}
68
-
name = "volume-down";
69
-
event = "button/volumedown.*";
71
-
#! ${pkgs.bash}/bin/sh
72
-
${config.services.acpid.volumeDownEventCommands}
78
-
event = "button/volumeup.*";
80
-
#! ${pkgs.bash}/bin/sh
81
-
${config.services.acpid.volumeUpEventCommands}
87
-
event = "cd/play.*";
89
-
#! ${pkgs.bash}/bin/sh
90
-
${config.services.acpid.cdPlayEventCommands}
96
-
event = "cd/next.*";
98
-
#! ${pkgs.bash}/bin/sh
99
-
${config.services.acpid.cdNextEventCommands}
105
-
event = "cd/prev.*";
107
-
#! ${pkgs.bash}/bin/sh
108
-
${config.services.acpid.cdPrevEventCommands}
24
+
acpiConfDir = pkgs.runCommand "acpi-events" {}
28
+
# Generate a configuration file for each event. (You can't have
29
+
# multiple events in one config file...)
30
+
let f = name: handler:
33
+
echo "event=${handler.event}" > $fn
34
+
echo "action=${pkgs.writeScript "${name}.sh" (concatStringsSep "\n" [ "#! ${pkgs.bash}/bin/sh" handler.action ])}" >> $fn
36
+
in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // config.services.acpid.handlers))
···
description = "Whether to enable the ACPI daemon.";
56
+
handlers = mkOption {
57
+
type = types.attrsOf (types.submodule {
61
+
example = [ "button/power.*" "button/lid.*" "ac_adapter.*" "button/mute.*" "button/volumedown.*" "cd/play.*" "cd/next.*" ];
62
+
description = "Event type.";
67
+
description = "Shell commands to execute when the event is triggered.";
72
+
description = "Event handlers.";
74
+
example = { mute = { event = "button/mute.*"; action = "amixer set Master toggle"; }; };
powerEventCommands = mkOption {
···
description = "Shell commands to execute on an ac_adapter.* event.";
147
-
muteCommands = mkOption {
148
-
type = types.lines;
150
-
description = "Shell commands to execute on an button/mute.* event.";
153
-
volumeDownEventCommands = mkOption {
154
-
type = types.lines;
156
-
description = "Shell commands to execute on an button/volumedown.* event.";
159
-
volumeUpEventCommands = mkOption {
160
-
type = types.lines;
162
-
description = "Shell commands to execute on an button/volumeup.* event.";
165
-
cdPlayEventCommands = mkOption {
166
-
type = types.lines;
168
-
description = "Shell commands to execute on an cd/play.* event.";
171
-
cdNextEventCommands = mkOption {
172
-
type = types.lines;
174
-
description = "Shell commands to execute on an cd/next.* event.";
177
-
cdPrevEventCommands = mkOption {
178
-
type = types.lines;
180
-
description = "Shell commands to execute on an cd/prev.* event.";