tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
Rewrite acpid module in a more generic way
koral
10 years ago
93e17506
148396c0
+44
-130
1 changed file
expand all
collapse all
unified
split
nixos
modules
services
hardware
acpid.nix
+44
-130
nixos/modules/services/hardware/acpid.nix
···
4
4
5
5
let
6
6
7
7
-
acpiConfDir = pkgs.runCommand "acpi-events" {}
8
8
-
''
9
9
-
mkdir -p $out
10
10
-
${
11
11
-
# Generate a configuration file for each event. (You can't have
12
12
-
# multiple events in one config file...)
13
13
-
let f = event:
14
14
-
''
15
15
-
fn=$out/${event.name}
16
16
-
echo "event=${event.event}" > $fn
17
17
-
echo "action=${pkgs.writeScript "${event.name}.sh" event.action}" >> $fn
18
18
-
'';
19
19
-
in lib.concatMapStrings f events
20
20
-
}
21
21
-
'';
22
22
-
23
23
-
events = [powerEvent lidEvent acEvent muteEvent volumeDownEvent volumeUpEvent cdPlayEvent cdNextEvent cdPrevEvent];
24
24
-
25
25
-
# Called when the power button is pressed.
26
26
-
powerEvent =
27
27
-
{ name = "power-button";
7
7
+
canonicalHandlers = {
8
8
+
powerEvent = {
28
9
event = "button/power.*";
29
29
-
action =
30
30
-
''
31
31
-
#! ${pkgs.bash}/bin/sh
32
32
-
${config.services.acpid.powerEventCommands}
33
33
-
'';
10
10
+
action = config.services.acpid.powerEventCommands;
34
11
};
35
12
36
36
-
# Called when the laptop lid is opened/closed.
37
37
-
lidEvent =
38
38
-
{ name = "lid";
13
13
+
lidEvent = {
39
14
event = "button/lid.*";
40
40
-
action =
41
41
-
''
42
42
-
#! ${pkgs.bash}/bin/sh
43
43
-
${config.services.acpid.lidEventCommands}
44
44
-
'';
15
15
+
action = config.services.acpid.lidEventCommands;
45
16
};
46
17
47
47
-
# Called when the AC power is connected or disconnected.
48
48
-
acEvent =
49
49
-
{ name = "ac-power";
18
18
+
acEvent = {
50
19
event = "ac_adapter.*";
51
51
-
action =
52
52
-
''
53
53
-
#! ${pkgs.bash}/bin/sh
54
54
-
${config.services.acpid.acEventCommands}
55
55
-
'';
20
20
+
action = config.services.acpid.acEventCommands;
56
21
};
57
57
-
58
58
-
muteEvent = {
59
59
-
name = "mute";
60
60
-
event = "button/mute.*";
61
61
-
action = ''
62
62
-
#! ${pkgs.bash}/bin/sh
63
63
-
${config.services.acpid.muteCommands}
64
64
-
'';
65
65
-
};
66
66
-
67
67
-
volumeDownEvent = {
68
68
-
name = "volume-down";
69
69
-
event = "button/volumedown.*";
70
70
-
action = ''
71
71
-
#! ${pkgs.bash}/bin/sh
72
72
-
${config.services.acpid.volumeDownEventCommands}
73
73
-
'';
74
22
};
75
23
76
76
-
volumeUpEvent = {
77
77
-
name = "volume-up";
78
78
-
event = "button/volumeup.*";
79
79
-
action = ''
80
80
-
#! ${pkgs.bash}/bin/sh
81
81
-
${config.services.acpid.volumeUpEventCommands}
82
82
-
'';
83
83
-
};
84
84
-
85
85
-
cdPlayEvent = {
86
86
-
name = "cd-play";
87
87
-
event = "cd/play.*";
88
88
-
action = ''
89
89
-
#! ${pkgs.bash}/bin/sh
90
90
-
${config.services.acpid.cdPlayEventCommands}
91
91
-
'';
92
92
-
};
93
93
-
94
94
-
cdNextEvent = {
95
95
-
name = "cd-next";
96
96
-
event = "cd/next.*";
97
97
-
action = ''
98
98
-
#! ${pkgs.bash}/bin/sh
99
99
-
${config.services.acpid.cdNextEventCommands}
100
100
-
'';
101
101
-
};
102
102
-
103
103
-
cdPrevEvent = {
104
104
-
name = "cd-prev";
105
105
-
event = "cd/prev.*";
106
106
-
action = ''
107
107
-
#! ${pkgs.bash}/bin/sh
108
108
-
${config.services.acpid.cdPrevEventCommands}
24
24
+
acpiConfDir = pkgs.runCommand "acpi-events" {}
25
25
+
''
26
26
+
mkdir -p $out
27
27
+
${
28
28
+
# Generate a configuration file for each event. (You can't have
29
29
+
# multiple events in one config file...)
30
30
+
let f = name: handler:
31
31
+
''
32
32
+
fn=$out/${name}
33
33
+
echo "event=${handler.event}" > $fn
34
34
+
echo "action=${pkgs.writeScript "${name}.sh" (concatStringsSep "\n" [ "#! ${pkgs.bash}/bin/sh" handler.action ])}" >> $fn
35
35
+
'';
36
36
+
in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // config.services.acpid.handlers))
37
37
+
}
109
38
'';
110
110
-
};
111
111
-
112
39
113
40
in
114
41
···
126
53
description = "Whether to enable the ACPI daemon.";
127
54
};
128
55
56
56
+
handlers = mkOption {
57
57
+
type = types.attrsOf (types.submodule {
58
58
+
options = {
59
59
+
event = mkOption {
60
60
+
type = types.str;
61
61
+
example = [ "button/power.*" "button/lid.*" "ac_adapter.*" "button/mute.*" "button/volumedown.*" "cd/play.*" "cd/next.*" ];
62
62
+
description = "Event type.";
63
63
+
};
64
64
+
65
65
+
action = mkOption {
66
66
+
type = types.lines;
67
67
+
description = "Shell commands to execute when the event is triggered.";
68
68
+
};
69
69
+
};
70
70
+
});
71
71
+
72
72
+
description = "Event handlers.";
73
73
+
default = {};
74
74
+
example = { mute = { event = "button/mute.*"; action = "amixer set Master toggle"; }; };
75
75
+
76
76
+
77
77
+
};
78
78
+
129
79
powerEventCommands = mkOption {
130
80
type = types.lines;
131
81
default = "";
···
142
92
type = types.lines;
143
93
default = "";
144
94
description = "Shell commands to execute on an ac_adapter.* event.";
145
145
-
};
146
146
-
147
147
-
muteCommands = mkOption {
148
148
-
type = types.lines;
149
149
-
default = "";
150
150
-
description = "Shell commands to execute on an button/mute.* event.";
151
151
-
};
152
152
-
153
153
-
volumeDownEventCommands = mkOption {
154
154
-
type = types.lines;
155
155
-
default = "";
156
156
-
description = "Shell commands to execute on an button/volumedown.* event.";
157
157
-
};
158
158
-
159
159
-
volumeUpEventCommands = mkOption {
160
160
-
type = types.lines;
161
161
-
default = "";
162
162
-
description = "Shell commands to execute on an button/volumeup.* event.";
163
163
-
};
164
164
-
165
165
-
cdPlayEventCommands = mkOption {
166
166
-
type = types.lines;
167
167
-
default = "";
168
168
-
description = "Shell commands to execute on an cd/play.* event.";
169
169
-
};
170
170
-
171
171
-
cdNextEventCommands = mkOption {
172
172
-
type = types.lines;
173
173
-
default = "";
174
174
-
description = "Shell commands to execute on an cd/next.* event.";
175
175
-
};
176
176
-
177
177
-
cdPrevEventCommands = mkOption {
178
178
-
type = types.lines;
179
179
-
default = "";
180
180
-
description = "Shell commands to execute on an cd/prev.* event.";
181
95
};
182
96
183
97
};