You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
3.6 KiB
156 lines
3.6 KiB
10 years ago
|
{ config, lib, pkgs, ... }:
|
||
16 years ago
|
|
||
10 years ago
|
with lib;
|
||
16 years ago
|
|
||
16 years ago
|
let
|
||
3 years ago
|
cfg = config.services.acpid;
|
||
16 years ago
|
|
||
9 years ago
|
canonicalHandlers = {
|
||
|
powerEvent = {
|
||
16 years ago
|
event = "button/power.*";
|
||
3 years ago
|
action = cfg.powerEventCommands;
|
||
16 years ago
|
};
|
||
13 years ago
|
|
||
9 years ago
|
lidEvent = {
|
||
16 years ago
|
event = "button/lid.*";
|
||
3 years ago
|
action = cfg.lidEventCommands;
|
||
16 years ago
|
};
|
||
13 years ago
|
|
||
9 years ago
|
acEvent = {
|
||
16 years ago
|
event = "ac_adapter.*";
|
||
3 years ago
|
action = cfg.acEventCommands;
|
||
16 years ago
|
};
|
||
9 years ago
|
};
|
||
|
|
||
6 years ago
|
acpiConfDir = pkgs.runCommand "acpi-events" { preferLocalBuild = true; }
|
||
9 years ago
|
''
|
||
|
mkdir -p $out
|
||
|
${
|
||
|
# Generate a configuration file for each event. (You can't have
|
||
|
# multiple events in one config file...)
|
||
|
let f = name: handler:
|
||
|
''
|
||
|
fn=$out/${name}
|
||
|
echo "event=${handler.event}" > $fn
|
||
6 years ago
|
echo "action=${pkgs.writeShellScriptBin "${name}.sh" handler.action }/bin/${name}.sh '%e'" >> $fn
|
||
9 years ago
|
'';
|
||
3 years ago
|
in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // cfg.handlers))
|
||
9 years ago
|
}
|
||
9 years ago
|
'';
|
||
|
|
||
16 years ago
|
in
|
||
|
|
||
15 years ago
|
{
|
||
16 years ago
|
|
||
15 years ago
|
###### interface
|
||
16 years ago
|
|
||
15 years ago
|
options = {
|
||
13 years ago
|
|
||
15 years ago
|
services.acpid = {
|
||
16 years ago
|
|
||
3 years ago
|
enable = mkEnableOption "the ACPI daemon";
|
||
14 years ago
|
|
||
6 years ago
|
logEvents = mkOption {
|
||
|
type = types.bool;
|
||
|
default = false;
|
||
|
description = "Log all event activity.";
|
||
|
};
|
||
|
|
||
9 years ago
|
handlers = mkOption {
|
||
|
type = types.attrsOf (types.submodule {
|
||
|
options = {
|
||
|
event = mkOption {
|
||
|
type = types.str;
|
||
3 years ago
|
example = literalExpression ''"button/power.*" "button/lid.*" "ac_adapter.*" "button/mute.*" "button/volumedown.*" "cd/play.*" "cd/next.*"'';
|
||
9 years ago
|
description = "Event type.";
|
||
|
};
|
||
14 years ago
|
|
||
9 years ago
|
action = mkOption {
|
||
|
type = types.lines;
|
||
|
description = "Shell commands to execute when the event is triggered.";
|
||
|
};
|
||
|
};
|
||
|
});
|
||
14 years ago
|
|
||
6 years ago
|
description = ''
|
||
|
Event handlers.
|
||
9 years ago
|
|
||
6 years ago
|
<note><para>
|
||
|
Handler can be a single command.
|
||
|
</para></note>
|
||
|
'';
|
||
|
default = {};
|
||
|
example = {
|
||
|
ac-power = {
|
||
|
event = "ac_adapter/*";
|
||
|
action = ''
|
||
|
vals=($1) # space separated string to array of multiple values
|
||
|
case ''${vals[3]} in
|
||
|
00000000)
|
||
|
echo unplugged >> /tmp/acpi.log
|
||
|
;;
|
||
|
00000001)
|
||
|
echo plugged in >> /tmp/acpi.log
|
||
|
;;
|
||
|
*)
|
||
|
echo unknown >> /tmp/acpi.log
|
||
|
;;
|
||
|
esac
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
powerEventCommands = mkOption {
|
||
9 years ago
|
type = types.lines;
|
||
|
default = "";
|
||
9 years ago
|
description = "Shell commands to execute on a button/power.* event.";
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
lidEventCommands = mkOption {
|
||
9 years ago
|
type = types.lines;
|
||
|
default = "";
|
||
9 years ago
|
description = "Shell commands to execute on a button/lid.* event.";
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
acEventCommands = mkOption {
|
||
9 years ago
|
type = types.lines;
|
||
|
default = "";
|
||
9 years ago
|
description = "Shell commands to execute on an ac_adapter.* event.";
|
||
9 years ago
|
};
|
||
|
|
||
15 years ago
|
};
|
||
13 years ago
|
|
||
15 years ago
|
};
|
||
13 years ago
|
|
||
15 years ago
|
|
||
|
###### implementation
|
||
|
|
||
3 years ago
|
config = mkIf cfg.enable {
|
||
16 years ago
|
|
||
9 years ago
|
systemd.services.acpid = {
|
||
|
description = "ACPI Daemon";
|
||
3 years ago
|
documentation = [ "man:acpid(8)" ];
|
||
15 years ago
|
|
||
9 years ago
|
wantedBy = [ "multi-user.target" ];
|
||
13 years ago
|
|
||
9 years ago
|
serviceConfig = {
|
||
3 years ago
|
ExecStart = escapeShellArgs
|
||
|
([ "${pkgs.acpid}/bin/acpid"
|
||
|
"--foreground"
|
||
|
"--netlink"
|
||
|
"--confdir" "${acpiConfDir}"
|
||
|
] ++ optional cfg.logEvents "--logevents"
|
||
|
);
|
||
9 years ago
|
};
|
||
|
unitConfig = {
|
||
|
ConditionVirtualization = "!systemd-nspawn";
|
||
|
ConditionPathExists = [ "/proc/acpi" ];
|
||
15 years ago
|
};
|
||
13 years ago
|
|
||
9 years ago
|
};
|
||
|
|
||
16 years ago
|
};
|
||
13 years ago
|
|
||
16 years ago
|
}
|