Commit 178ea7bb authored by Anderson Torres's avatar Anderson Torres
Browse files

nixos/triggerhappy: update and format

mpc-cli is now mpc
parent bcd149f7
Loading
Loading
Loading
Loading
+62 −36
Original line number Diff line number Diff line
{ config, lib, pkgs, ... }:
{
  config,
  lib,
  pkgs,
  ...
}:
let

  cfg = config.services.triggerhappy;
@@ -6,15 +11,29 @@ 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 = { ... }: {
  bindingCfg =
    { ... }:
    {
      options = {

        keys = lib.mkOption {
@@ -23,7 +42,11 @@ let
        };

        event = lib.mkOption {
        type = lib.types.enum ["press" "hold" "release"];
          type = lib.types.enum [
            "press"
            "hold"
            "release"
          ];
          default = "press";
          description = "Event to match.";
        };
@@ -67,7 +90,7 @@ in
        type = lib.types.listOf (lib.types.submodule bindingCfg);
        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 {
    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"
        '';
    });
      }
    );

  };