Troubleshooting help: services.interception-tools

nix-info -m

  • system: "x86_64-linux"
  • host os: Linux 5.15.53, NixOS, 22.11 (Raccoon), 22.11.20220714.4a01ca3
  • multi-user?: yes
  • sandbox: yes
  • version: `nix-env (Nix) 2.9.1
  • Wayland, Hyprland window manager`

I’m configuring my system through flake for both the system and home-manager. I’m trying to use the interception-tools service, and I have the following in my configuration.nix file:

  services.interception-tools = {
    enable = true;
    plugins = with pkgs; [
      interception-tools-plugins.caps2esc
    ];
    udevmonConfig = ''
      - JOB: "intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE"
        DEVICE:
          EVENTS:
            EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
    '';
  };

These are the basic options, essentially copying the example in the nixpkgs description. My expectation was that with these options, the service would be set up and “just work”. My problem is that the caps2esc plugin is not in effect, even after a system restart. I’ve checked with htop and udevmon is running with the specified config file loaded so it appears that at least part of the setup is complete.

At this point, I don’t really know how to troubleshoot. I can find a caps2esc binary in my nix store, but that really doesn’t help me. My nix-fu is minimal (a gross overestimation of my actual abilities) and I so don’t know how to verify that the plugin is installed correctly and is actually available to the interception tools pipeline.

It’s likely I’m missing something obvious, so any wisdom to point me in the right direction would be appreciated.

You should check the output of systemctl status interception-tools.service.

If that doesn’t tell you anything obvious, you might have more luck if you specify the device name in the udevmonConfig, you can find it with: sudo uinput -p -d /dev/input/by-id/<device>. At least I personally never had any luck with a device agnostic configuration like this.

1 Like

Thanks very much for the help. systemctl does indeed yield something obvious:

❯ systemctl status interception-tools.service
● interception-tools.service - Interception tools
     Loaded: loaded (/etc/systemd/system/interception-tools.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-07-18 09:40:18 +07; 44s ago
   Main PID: 678 (udevmon)
         IP: 0B in, 0B out
         IO: 3.4M read, 0B written
      Tasks: 1 (limit: 9431)
     Memory: 3.9M
        CPU: 35ms
     CGroup: /system.slice/interception-tools.service
             └─678 /nix/store/rdz1lrdccx98s6lq5adnfpkwwqkrp5av-interception-tools-0.6.8/bin/udevmon -c /nix/store/d2ss5mvz3viax3v91nbp31x4x4ya0jzr-udevmon.yaml

Jul 18 09:40:18 sp4 systemd[1]: Started Interception tools.
Jul 18 09:40:19 sp4 udevmon[822]: sh: line 1: intercept: command not found
Jul 18 09:40:19 sp4 udevmon[823]: sh: line 1: caps2esc: command not found
Jul 18 09:40:19 sp4 udevmon[824]: sh: line 1: uinput: command not found
Jul 18 09:40:19 sp4 udevmon[830]: sh: line 1: intercept: command not found
Jul 18 09:40:19 sp4 udevmon[831]: sh: line 1: caps2esc: command not found
Jul 18 09:40:19 sp4 udevmon[832]: sh: line 1: uinput: command not found
Jul 18 09:40:19 sp4 udevmon[844]: sh: line 1: intercept: command not found
Jul 18 09:40:19 sp4 udevmon[846]: sh: line 1: uinput: command not found
Jul 18 09:40:19 sp4 udevmon[845]: sh: line 1: caps2esc: command not found

The service looks like this:

[Unit]
Description=Interception tools

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/jd7gs3xxzarszals52qxl1p8pwr0jdwl-glibc-locales-2.34-210/lib/locale/locale-archive"
Environment="PATH=/nix/store/3j18grljsyy4nxc078g00sy4cx6cf16g-bash-5.1-p16/bin:/nix/store/rdz1lrdccx98s6lq5adnfpkwwqkrp5av-interception-tools-0.6.8/bin:/nix/store/z64bbmqpkpa4xcjsxym5b7f0vw7aic8g-caps2esc-0.3.2/bin:/nix/store/ib7q40m9vbkvqmq6lbmcwvmzxqnfmzs7-coreutils-stage4-9.1/bin:/nix/store/m5r6yjqmd3aaaww8fhd5z5j2x7sylrxz-findutils-4.9.0/bin:/nix/store/rb23g7673465ls5v2wc2pjqc03r5r35i-gnugrep-3.7/bin:/nix/store/5nmpxygcis4d967xjl5szj5j76kj383r-gnused-4.8/bin:/nix/store/89366aivz6v8a34yyni2m04ca9hwrl92-systemd-250.4/bin:/nix/store/3j18grljsyy4nxc078g00sy4cx6cf16g-bash-5.1-p16/sbin:/nix/store/rdz1lrdccx98s6lq5adnfpkwwqkrp5av-interception-tools-0.6.8/sbin:/nix/store/z64bbmqpkpa4xcjsxym5b7f0vw7aic8g-caps2esc-0.3.2/sbin:/nix/store/ib7q40m9vbkvqmq6lbmcwvmzxqnfmzs7-coreutils-stage4-9.1/sbin:/nix/store/m5r6yjqmd3aaaww8fhd5z5j2x7sylrxz-findutils-4.9.0/sbin:/nix/store/rb23g7673465ls5v2wc2pjqc03r5r35i-gnugrep-3.7/sbin:/nix/store/5nmpxygcis4d967xjl5szj5j76kj383r-gnused-4.8/sbin:/nix/store/89366aivz6v8a34yyni2m04ca9hwrl92-systemd-250.4/sbin"
Environment="TZDIR=/nix/store/nx7c93fcjjkkypsmyb9d0jgb6jmnqv2v-tzdata-2022a/share/zoneinfo"

ExecStart=/nix/store/rdz1lrdccx98s6lq5adnfpkwwqkrp5av-interception-tools-0.6.8/bin/udevmon -c \
/nix/store/d2ss5mvz3viax3v91nbp31x4x4ya0jzr-udevmon.yaml

Nice=-20

As far as I can see, the ....-interception-tools-0.6.8/bin directory is in the path, and when I look there, it appears that the required tools exist on the path:

❯ ll /nix/store/rdz1lrdccx98s6lq5adnfpkwwqkrp5av-interception-tools-0.6.8/bin
.r-xr-xr-x  16k root  1 Jan  1970 intercept
.r-xr-xr-x  75k root  1 Jan  1970 mux
.r-xr-xr-x 356k root  1 Jan  1970 udevmon
.r-xr-xr-x 134k root  1 Jan  1970 uinput

The caps2esc binary seems to exist on the path also:

❯ ll /nix/store/z64bbmqpkpa4xcjsxym5b7f0vw7aic8g-caps2esc-0.3.2/bin
.r-xr-xr-x 16k root  1 Jan  1970 caps2esc

This also seems to mean that I’m not able to try your suggestion to specify the device:

❯ sudo uinput -p -d /dev/input/by-id/"Corsair CORSAIR K60 PRO Mechanical Gaming Keyboard"
sudo: uinput: command not found

I’m still not sure how to interpret this info, or where to go, though I won’t be surprised if I’m missing something obvious.

Thanks again.

I’m still not sure how to interpret this info, or where to go, though I won’t be surprised if I’m missing something obvious.

It’s not really that obvious as this does indeed seem like it should work, and it’s probably worth a deeper look to determine exactly why it doesn’t, but to just get things to work you can specify the full path to the binaries in the configuration with ${pkgs.interception-tools}/bin/intercept etc. (something that if I actually take a look at my own config instead of just going by memory, it turns out that I’m doing).

This also seems to mean that I’m not able to try your suggestion to specify the device:

No, this is actually expected as simply enabling a services typically wont add any packages to environment.systemPackages. Which makes sense given that you don’t need some daemon in your path if it’s started by the service manager. Anyway, to temporarily enter an environment with uinput you can do that with nix-shell -p interception-tools.

Well, giving the full paths to each binary has everything working as expected, so I’m all set.

Thanks a lot for following up on this.

Just for reference, some follow-up searching based on your suggestion led me to this. Wish I’d found it sooner…would have saved us both some time and effort :slight_smile:

For anyone else with the same issue, this is the config that’s working for me:

    udevmonConfig = ''
      - JOB: "${pkgs.interception-tools}/bin/intercept -g $DEVNODE | ${pkgs.interception-tools-plugins.caps2esc}/bin/caps2esc -m 1 | ${pkgs.interception-tools}/bin/uinput -d $DEVNODE"
        DEVICE:
          EVENTS:
            EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
    '';

Also a good way to find niche solutions is to search your code you are attempting to write on github.

For example using the advanced Github search functionality, you can search language:"Nix" udevmonConfig and find these kind of answers quickly. For example this is the output for that search: https://github.com/search?q=language%3A"Nix"+udevmonConfig&type=code

Only issue with this approach is that i have yet to properly figure out a way to better filter out all the forks of nixpkgs.

you may get more joy from Sourcegraph

which has way better search filters and has the concept of ‘contexts’, (but you have to log in for that).

1 Like

Thanks for this, it’s helpful. I haven’t used that functionality before.

1 Like