@@ -3,21 +3,22 @@
33with lib;
44
55let
6+ cfg = config.services.acpid;
67
78 canonicalHandlers = {
89 powerEvent = {
910 event = "button/power.*";
10− action = config.services.acpid.powerEventCommands;
11+ action = cfg.powerEventCommands;
1112 };
1213
1314 lidEvent = {
1415 event = "button/lid.*";
15− action = config.services.acpid.lidEventCommands;
16+ action = cfg.lidEventCommands;
1617 };
1718
1819 acEvent = {
1920 event = "ac_adapter.*";
20− action = config.services.acpid.acEventCommands;
21+ action = cfg.acEventCommands;
2122 };
2223 };
2324
@@ -33,7 +34,7 @@ let
3334 echo "event=${handler.event}" > $fn
3435 echo "action=${pkgs.writeShellScriptBin "${name}.sh" handler.action }/bin/${name}.sh '%e'" >> $fn
3536 '';
36− in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // config.services.acpid.handlers))
37+ in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // cfg.handlers))
3738 }
3839 '';
3940
@@ -47,11 +48,7 @@ in
4748
4849 services.acpid = {
4950
50− enable = mkOption {
51− type = types.bool;
52− default = false;
53− description = "Whether to enable the ACPI daemon.";
54− };
51+ enable = mkEnableOption "the ACPI daemon";
5552
5653 logEvents = mkOption {
5754 type = types.bool;
@@ -129,26 +126,28 @@ in
129126
130127 ###### implementation
131128
132− config = mkIf config.services.acpid.enable {
129+ config = mkIf cfg.enable {
133130
134131 systemd.services.acpid = {
135132 description = "ACPI Daemon";
133+ documentation = [ "man:acpid(8)" ];
136134
137135 wantedBy = [ "multi-user.target" ];
138− after = [ "systemd-udev-settle.service" ];
139−
140− path = [ pkgs.acpid ];
141136
142137 serviceConfig = {
143− Type = "forking";
138+ ExecStart = escapeShellArgs
139+ ([ "${pkgs.acpid}/bin/acpid"
140+ "--foreground"
141+ "--netlink"
142+ "--confdir" "${acpiConfDir}"
143+ ] ++ optional cfg.logEvents "--logevents"
144+ );
144145 };
145−
146146 unitConfig = {
147147 ConditionVirtualization = "!systemd-nspawn";
148148 ConditionPathExists = [ "/proc/acpi" ];
149149 };
150150
151− script = "acpid ${optionalString config.services.acpid.logEvents "--logevents"} --confdir ${acpiConfDir}";
152151 };
153152
154153 };