From 178ea7bbd53839046cc3dffe400c7fd8cc1064fd Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Wed, 16 Oct 2024 20:56:28 -0300 Subject: [PATCH] nixos/triggerhappy: update and format mpc-cli is now mpc --- .../services/hardware/triggerhappy.nix | 98 ++++++++++++------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/nixos/modules/services/hardware/triggerhappy.nix b/nixos/modules/services/hardware/triggerhappy.nix index d2137971b3a7..a9bcf250cf69 100644 --- a/nixos/modules/services/hardware/triggerhappy.nix +++ b/nixos/modules/services/hardware/triggerhappy.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.services.triggerhappy; @@ -6,35 +11,53 @@ let socket = "/run/thd.socket"; configFile = pkgs.writeText "triggerhappy.conf" '' - ${lib.concatMapStringsSep "\n" - ({ keys, event, cmd, ... }: - ''${lib.concatMapStringsSep "+" (x: "KEY_" + x) keys} ${toString { press = 1; hold = 2; release = 0; }.${event}} ${cmd}'' - ) - cfg.bindings} + ${lib.concatMapStringsSep "\n" ( + { + keys, + event, + cmd, + ... + }: + ''${lib.concatMapStringsSep "+" (x: "KEY_" + x) keys} ${ + toString + { + press = 1; + hold = 2; + release = 0; + } + .${event} + } ${cmd}'' + ) cfg.bindings} ${cfg.extraConfig} ''; - bindingCfg = { ... }: { - options = { + bindingCfg = + { ... }: + { + options = { + + keys = lib.mkOption { + type = lib.types.listOf lib.types.str; + description = "List of keys to match. Key names as defined in linux/input-event-codes.h"; + }; + + event = lib.mkOption { + type = lib.types.enum [ + "press" + "hold" + "release" + ]; + default = "press"; + description = "Event to match."; + }; + + cmd = lib.mkOption { + type = lib.types.str; + description = "What to run."; + }; - keys = lib.mkOption { - type = lib.types.listOf lib.types.str; - description = "List of keys to match. Key names as defined in linux/input-event-codes.h"; }; - - event = lib.mkOption { - type = lib.types.enum ["press" "hold" "release"]; - default = "press"; - description = "Event to match."; - }; - - cmd = lib.mkOption { - type = lib.types.str; - description = "What to run."; - }; - }; - }; in @@ -65,9 +88,9 @@ in bindings = lib.mkOption { type = lib.types.listOf (lib.types.submodule bindingCfg); - default = []; + default = [ ]; example = lib.literalExpression '' - [ { keys = ["PLAYPAUSE"]; cmd = "''${pkgs.mpc-cli}/bin/mpc -q toggle"; } ] + [ { keys = ["PLAYPAUSE"]; cmd = "''${lib.getExe pkgs.mpc} -q toggle"; } ] ''; description = '' Key bindings for {command}`triggerhappy`. @@ -86,7 +109,6 @@ in }; - ###### implementation config = lib.mkIf cfg.enable { @@ -101,18 +123,22 @@ in wantedBy = [ "multi-user.target" ]; description = "Global hotkey daemon"; serviceConfig = { - ExecStart = "${pkgs.triggerhappy}/bin/thd ${lib.optionalString (cfg.user != "root") "--user ${cfg.user}"} --socket ${socket} --triggers ${configFile} --deviceglob /dev/input/event*"; + ExecStart = "${pkgs.triggerhappy}/bin/thd ${ + lib.optionalString (cfg.user != "root") "--user ${cfg.user}" + } --socket ${socket} --triggers ${configFile} --deviceglob /dev/input/event*"; }; }; - services.udev.packages = lib.singleton (pkgs.writeTextFile { - name = "triggerhappy-udev-rules"; - destination = "/etc/udev/rules.d/61-triggerhappy.rules"; - text = '' - ACTION=="add", SUBSYSTEM=="input", KERNEL=="event[0-9]*", ATTRS{name}!="triggerhappy", \ - RUN+="${pkgs.triggerhappy}/bin/th-cmd --socket ${socket} --passfd --udev" - ''; - }); + services.udev.packages = lib.singleton ( + pkgs.writeTextFile { + name = "triggerhappy-udev-rules"; + destination = "/etc/udev/rules.d/61-triggerhappy.rules"; + text = '' + ACTION=="add", SUBSYSTEM=="input", KERNEL=="event[0-9]*", ATTRS{name}!="triggerhappy", \ + RUN+="${pkgs.triggerhappy}/bin/th-cmd --socket ${socket} --passfd --udev" + ''; + } + ); };