9 cfg = config.services.triggerhappy;
11 socket = "/run/thd.socket";
13 configFile = pkgs.writeText "triggerhappy.conf" ''
14 ${lib.concatMapStringsSep "\n" (
21 ''${lib.concatMapStringsSep "+" (x: "KEY_" + x) keys} ${
40 type = lib.types.listOf lib.types.str;
41 description = "List of keys to match. Key names as defined in linux/input-event-codes.h";
44 event = lib.mkOption {
45 type = lib.types.enum [
51 description = "Event to match.";
56 description = "What to run.";
70 services.triggerhappy = {
72 enable = lib.mkOption {
73 type = lib.types.bool;
76 Whether to enable the {command}`triggerhappy` hotkey daemon.
85 User account under which {command}`triggerhappy` runs.
89 bindings = lib.mkOption {
90 type = lib.types.listOf (lib.types.submodule bindingCfg);
92 example = lib.literalExpression ''
93 [ { keys = ["PLAYPAUSE"]; cmd = "''${lib.getExe pkgs.mpc} -q toggle"; } ]
96 Key bindings for {command}`triggerhappy`.
100 extraConfig = lib.mkOption {
101 type = lib.types.lines;
104 Literal contents to append to the end of {command}`triggerhappy` configuration file.
112 ###### implementation
114 config = lib.mkIf cfg.enable {
116 systemd.sockets.triggerhappy = {
117 description = "Triggerhappy Socket";
118 wantedBy = [ "sockets.target" ];
119 socketConfig.ListenDatagram = socket;
122 systemd.services.triggerhappy = {
123 wantedBy = [ "multi-user.target" ];
124 description = "Global hotkey daemon";
126 ExecStart = "${pkgs.triggerhappy}/bin/thd ${
127 lib.optionalString (cfg.user != "root") "--user ${cfg.user}"
128 } --socket ${socket} --triggers ${configFile} --deviceglob /dev/input/event*";
132 services.udev.packages = lib.singleton (
134 name = "triggerhappy-udev-rules";
135 destination = "/etc/udev/rules.d/61-triggerhappy.rules";
137 ACTION=="add", SUBSYSTEM=="input", KERNEL=="event[0-9]*", ATTRS{name}!="triggerhappy", \
138 RUN+="${pkgs.triggerhappy}/bin/th-cmd --socket ${socket} --passfd --udev"