summary refs log tree commit diff
diff options
context:
space:
mode:
authorrnhmjoj <rnhmjoj@inventati.org>2021-02-27 16:18:32 +0100
committerrnhmjoj <rnhmjoj@inventati.org>2021-02-27 16:18:32 +0100
commit8e016023f865b6feb3cff4fac39c5e2315033074 (patch)
tree69e2a36fac5507f223f85c08ad23b3d0c0d037f9
parent1c2649737180bb5fd196fb8d3e814977aa3c77d8 (diff)
downloadnixpkgs-8e016023f865b6feb3cff4fac39c5e2315033074.tar
nixpkgs-8e016023f865b6feb3cff4fac39c5e2315033074.tar.gz
nixpkgs-8e016023f865b6feb3cff4fac39c5e2315033074.tar.bz2
nixpkgs-8e016023f865b6feb3cff4fac39c5e2315033074.tar.lz
nixpkgs-8e016023f865b6feb3cff4fac39c5e2315033074.tar.xz
nixpkgs-8e016023f865b6feb3cff4fac39c5e2315033074.tar.zst
nixpkgs-8e016023f865b6feb3cff4fac39c5e2315033074.zip
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
-rw-r--r--nixos/modules/services/hardware/acpid.nix31
1 files changed, 15 insertions, 16 deletions
diff --git a/nixos/modules/services/hardware/acpid.nix b/nixos/modules/services/hardware/acpid.nix
index 4c97485d972..3e619fe32ef 100644
--- a/nixos/modules/services/hardware/acpid.nix
+++ b/nixos/modules/services/hardware/acpid.nix
@@ -3,21 +3,22 @@
 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;
     };
   };
 
@@ -33,7 +34,7 @@ let
             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))
       }
     '';
 
@@ -47,11 +48,7 @@ in
 
     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;
@@ -129,26 +126,28 @@ in
 
   ###### 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}";
     };
 
   };