about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/hardware/evscript.nix
blob: 5f5f511013c797d66109c0734b255034106bc79b (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
{ pkgs, lib, config, ... }:

let
  cfg = config.services.evscript;

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

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

      devices = mkOption {
        description = "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 = "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}
      '';
    };
  };
}