nixos/acpid: clean up the module

- Use --netlink to avoid systemd-udev-settle[1]

- Run daemon in foreground which is preferred with systemd

- Add unit documentation

- Write ExecStart directly, no need for a script

[1]: https://github.com/archlinux/svntogit-community/commit/52bbd2b80bea968ce95fbc52e80c5afddb771337

rnhmjoj 8e016023 1c264973

Changed files
+15 -16
nixos
modules
services
hardware
+15 -16
nixos/modules/services/hardware/acpid.nix
···
with lib;
let
+
cfg = config.services.acpid;
canonicalHandlers = {
powerEvent = {
event = "button/power.*";
-
action = config.services.acpid.powerEventCommands;
+
action = cfg.powerEventCommands;
};
lidEvent = {
event = "button/lid.*";
-
action = config.services.acpid.lidEventCommands;
+
action = cfg.lidEventCommands;
};
acEvent = {
event = "ac_adapter.*";
-
action = config.services.acpid.acEventCommands;
+
action = cfg.acEventCommands;
};
};
···
echo "event=${handler.event}" > $fn
echo "action=${pkgs.writeShellScriptBin "${name}.sh" handler.action }/bin/${name}.sh '%e'" >> $fn
'';
-
in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // config.services.acpid.handlers))
+
in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // cfg.handlers))
}
'';
···
services.acpid = {
-
enable = mkOption {
-
type = types.bool;
-
default = false;
-
description = "Whether to enable the ACPI daemon.";
-
};
+
enable = mkEnableOption "the ACPI daemon";
logEvents = mkOption {
type = types.bool;
···
###### implementation
-
config = mkIf config.services.acpid.enable {
+
config = mkIf cfg.enable {
systemd.services.acpid = {
description = "ACPI Daemon";
+
documentation = [ "man:acpid(8)" ];
wantedBy = [ "multi-user.target" ];
-
after = [ "systemd-udev-settle.service" ];
-
-
path = [ pkgs.acpid ];
serviceConfig = {
-
Type = "forking";
+
ExecStart = escapeShellArgs
+
([ "${pkgs.acpid}/bin/acpid"
+
"--foreground"
+
"--netlink"
+
"--confdir" "${acpiConfDir}"
+
] ++ optional cfg.logEvents "--logevents"
+
);
};
-
unitConfig = {
ConditionVirtualization = "!systemd-nspawn";
ConditionPathExists = [ "/proc/acpi" ];
};
-
script = "acpid ${optionalString config.services.acpid.logEvents "--logevents"} --confdir ${acpiConfDir}";
};
};