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]: 52bbd2b80b
This commit is contained in:
parent
1c26497371
commit
8e016023f8
@ -3,21 +3,22 @@
|
|||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
cfg = config.services.acpid;
|
||||||
|
|
||||||
canonicalHandlers = {
|
canonicalHandlers = {
|
||||||
powerEvent = {
|
powerEvent = {
|
||||||
event = "button/power.*";
|
event = "button/power.*";
|
||||||
action = config.services.acpid.powerEventCommands;
|
action = cfg.powerEventCommands;
|
||||||
};
|
};
|
||||||
|
|
||||||
lidEvent = {
|
lidEvent = {
|
||||||
event = "button/lid.*";
|
event = "button/lid.*";
|
||||||
action = config.services.acpid.lidEventCommands;
|
action = cfg.lidEventCommands;
|
||||||
};
|
};
|
||||||
|
|
||||||
acEvent = {
|
acEvent = {
|
||||||
event = "ac_adapter.*";
|
event = "ac_adapter.*";
|
||||||
action = config.services.acpid.acEventCommands;
|
action = cfg.acEventCommands;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ let
|
|||||||
echo "event=${handler.event}" > $fn
|
echo "event=${handler.event}" > $fn
|
||||||
echo "action=${pkgs.writeShellScriptBin "${name}.sh" handler.action }/bin/${name}.sh '%e'" >> $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))
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -47,11 +48,7 @@ in
|
|||||||
|
|
||||||
services.acpid = {
|
services.acpid = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkEnableOption "the ACPI daemon";
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = "Whether to enable the ACPI daemon.";
|
|
||||||
};
|
|
||||||
|
|
||||||
logEvents = mkOption {
|
logEvents = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
@ -129,26 +126,28 @@ in
|
|||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf config.services.acpid.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
systemd.services.acpid = {
|
systemd.services.acpid = {
|
||||||
description = "ACPI Daemon";
|
description = "ACPI Daemon";
|
||||||
|
documentation = [ "man:acpid(8)" ];
|
||||||
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "systemd-udev-settle.service" ];
|
|
||||||
|
|
||||||
path = [ pkgs.acpid ];
|
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "forking";
|
ExecStart = escapeShellArgs
|
||||||
|
([ "${pkgs.acpid}/bin/acpid"
|
||||||
|
"--foreground"
|
||||||
|
"--netlink"
|
||||||
|
"--confdir" "${acpiConfDir}"
|
||||||
|
] ++ optional cfg.logEvents "--logevents"
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
unitConfig = {
|
unitConfig = {
|
||||||
ConditionVirtualization = "!systemd-nspawn";
|
ConditionVirtualization = "!systemd-nspawn";
|
||||||
ConditionPathExists = [ "/proc/acpi" ];
|
ConditionPathExists = [ "/proc/acpi" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
script = "acpid ${optionalString config.services.acpid.logEvents "--logevents"} --confdir ${acpiConfDir}";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user