1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.interception-tools;
7in {
8 options.services.interception-tools = {
9 enable = mkOption {
10 type = types.bool;
11 default = false;
12 description = "Whether to enable the interception tools service.";
13 };
14
15 plugins = mkOption {
16 type = types.listOf types.package;
17 default = [ pkgs.interception-tools-plugins.caps2esc ];
18 description = ''
19 A list of interception tools plugins that will be made available to use
20 inside the udevmon configuration.
21 '';
22 };
23
24 udevmonConfig = mkOption {
25 type = types.either types.str types.path;
26 default = ''
27 - JOB: "intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE"
28 DEVICE:
29 EVENTS:
30 EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
31 '';
32 example = ''
33 - JOB: "intercept -g $DEVNODE | y2z | x2y | uinput -d $DEVNODE"
34 DEVICE:
35 EVENTS:
36 EV_KEY: [KEY_X, KEY_Y]
37 '';
38 description = ''
39 String of udevmon YAML configuration, or path to a udevmon YAML
40 configuration file.
41 '';
42 };
43 };
44
45 config = mkIf cfg.enable {
46 systemd.services.interception-tools = {
47 description = "Interception tools";
48 path = [ pkgs.bash pkgs.interception-tools ] ++ cfg.plugins;
49 serviceConfig = {
50 ExecStart = ''
51 ${pkgs.interception-tools}/bin/udevmon -c \
52 ${if builtins.typeOf cfg.udevmonConfig == "path"
53 then cfg.udevmonConfig
54 else pkgs.writeText "udevmon.yaml" cfg.udevmonConfig}
55 '';
56 Nice = -20;
57 };
58 wantedBy = [ "multi-user.target" ];
59 };
60 };
61}