about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/hardware/evscript.nix
blob: 6722887afb4f88cfea024e6dec6a85e97b66d624 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ pkgs, lib, config, ... }:

let
  cfg = config.services.evscript;

in
{
  options = with lib; {
    services.evscript = {
      enable = mkEnableOption (mdDoc "the evscript service");

      package = mkOption {
        description = mdDoc "evscript package to use for the evscript service";
        type = types.package;
        default = pkgs.evscript;
        defaultText = literalExpression "pkgs.evscript";
      };

      devices = mkOption {
        description = mdDoc "evdev devices for evscript to listen to";
        type = types.listOf types.path;
        example = [ "/dev/input/by-path/pci-0000:00:1d.0-usb-0:1.1:1.0-event-kbd" ];
      };

      script = mkOption {
        description = mdDoc "Dyon script for evscript service to run";
        type = types.path;
      };
    };
  };

  config = lib.mkIf cfg.enable {
    boot.kernelModules = [ "uinput" ];

    services.udev.extraRules = ''
      KERNEL=="uinput", MODE="0660", GROUP="input"
    '';

    systemd.services.evscript = {
      after = [ "systemd-udevd" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig.DynamicUser = true;
      serviceConfig.SupplementaryGroups = [ "input" ];
      script = ''
        ${cfg.package}/bin/evscript \
            ${lib.concatMapStringsSep " " (d: "-d ${d}") cfg.devices} \
            -f ${cfg.script}
      '';
    };
  };
}