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