diff options
author | Daniel Schaefer <git@danielschaefer.me> | 2018-02-10 20:26:05 +0700 |
---|---|---|
committer | Jörg Thalheim <Mic92@users.noreply.github.com> | 2018-02-10 13:26:05 +0000 |
commit | 713a69d08357ea813175ae1f9f87888ece2d9b36 (patch) | |
tree | 1eb001e4ae1b9e25bb41a952557cea5b0ffb18e0 /nixos/modules/services/hardware | |
parent | 35d36994a49d819d7453d195c9f822aea2c7086b (diff) | |
download | nixlib-713a69d08357ea813175ae1f9f87888ece2d9b36.tar nixlib-713a69d08357ea813175ae1f9f87888ece2d9b36.tar.gz nixlib-713a69d08357ea813175ae1f9f87888ece2d9b36.tar.bz2 nixlib-713a69d08357ea813175ae1f9f87888ece2d9b36.tar.lz nixlib-713a69d08357ea813175ae1f9f87888ece2d9b36.tar.xz nixlib-713a69d08357ea813175ae1f9f87888ece2d9b36.tar.zst nixlib-713a69d08357ea813175ae1f9f87888ece2d9b36.zip |
nixos/acpid: pass event parameters to handler (#34190)
Previously the parameters were just dropped. Now they can be read from within the handler script. An example to show this is added. Makes use of the new writeShellScript function as suggested in: issue #21557 resolves: #21557
Diffstat (limited to 'nixos/modules/services/hardware')
-rw-r--r-- | nixos/modules/services/hardware/acpid.nix | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/nixos/modules/services/hardware/acpid.nix b/nixos/modules/services/hardware/acpid.nix index bb17c8859d84..f69706ebff34 100644 --- a/nixos/modules/services/hardware/acpid.nix +++ b/nixos/modules/services/hardware/acpid.nix @@ -31,7 +31,7 @@ let '' fn=$out/${name} echo "event=${handler.event}" > $fn - echo "action=${pkgs.writeScript "${name}.sh" (concatStringsSep "\n" [ "#! ${pkgs.bash}/bin/sh" handler.action ])}" >> $fn + echo "action=${pkgs.writeShellScriptBin "${name}.sh" handler.action }/bin/${name}.sh '%e'" >> $fn ''; in concatStringsSep "\n" (mapAttrsToList f (canonicalHandlers // config.services.acpid.handlers)) } @@ -69,11 +69,33 @@ in }; }); - description = "Event handlers."; - default = {}; - example = { mute = { event = "button/mute.*"; action = "amixer set Master toggle"; }; }; - + description = '' + Event handlers. + <note><para> + Handler can be a single command. + </para></note> + ''; + default = {}; + example = { + ac-power = { + event = "ac_adapter/*"; + action = '' + vals=($1) # space separated string to array of multiple values + case ''${vals[3]} in + 00000000) + echo unplugged >> /tmp/acpi.log + ;; + 00000001) + echo plugged in >> /tmp/acpi.log + ;; + *) + echo unknown >> /tmp/acpi.log + ;; + esac + ''; + }; + }; }; powerEventCommands = mkOption { |