1 { config, lib, pkgs, ... }:
6 cfg = config.services.acpid;
10 event = "button/power.*";
11 action = cfg.powerEventCommands;
15 event = "button/lid.*";
16 action = cfg.lidEventCommands;
20 event = "ac_adapter.*";
21 action = cfg.acEventCommands;
25 acpiConfDir = pkgs.runCommand "acpi-events" { preferLocalBuild = true; }
29 # Generate a configuration file for each event. (You can't have
30 # multiple events in one config file...)
31 let f = name: handler:
34 echo "event=${handler.event}" > $fn
35 echo "action=${pkgs.writeShellScriptBin "${name}.sh" handler.action }/bin/${name}.sh '%e'" >> $fn
37 in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // cfg.handlers))
51 enable = mkEnableOption (lib.mdDoc "the ACPI daemon");
53 logEvents = mkOption {
56 description = lib.mdDoc "Log all event activity.";
60 type = types.attrsOf (types.submodule {
64 example = literalExpression ''"button/power.*" "button/lid.*" "ac_adapter.*" "button/mute.*" "button/volumedown.*" "cd/play.*" "cd/next.*"'';
65 description = lib.mdDoc "Event type.";
70 description = lib.mdDoc "Shell commands to execute when the event is triggered.";
75 description = lib.mdDoc ''
79 Handler can be a single command.
85 event = "ac_adapter/*";
87 vals=($1) # space separated string to array of multiple values
90 echo unplugged >> /tmp/acpi.log
93 echo plugged in >> /tmp/acpi.log
96 echo unknown >> /tmp/acpi.log
104 powerEventCommands = mkOption {
107 description = lib.mdDoc "Shell commands to execute on a button/power.* event.";
110 lidEventCommands = mkOption {
113 description = lib.mdDoc "Shell commands to execute on a button/lid.* event.";
116 acEventCommands = mkOption {
119 description = lib.mdDoc "Shell commands to execute on an ac_adapter.* event.";
127 ###### implementation
129 config = mkIf cfg.enable {
131 systemd.services.acpid = {
132 description = "ACPI Daemon";
133 documentation = [ "man:acpid(8)" ];
135 wantedBy = [ "multi-user.target" ];
138 ExecStart = escapeShellArgs
139 ([ "${pkgs.acpid}/bin/acpid"
142 "--confdir" "${acpiConfDir}"
143 ] ++ optional cfg.logEvents "--logevents"
147 ConditionVirtualization = "!systemd-nspawn";
148 ConditionPathExists = [ "/proc/acpi" ];