Guest post by Andre Johansen, who runs KeebKit, a site about mechanical keyboards.

Ali has written about this setup twice: A Modern Space Cadet but for Linux in 2020 and Dual Function Keys on NixOS in 2022. Both use Interception Tools with the dual-function-keys plugin. Since then two other tools have become common for the same job, keyd and kanata, and both have a NixOS module.

This post takes the three mappings from those posts and writes them for all three tools, so you can compare them and paste the one you like.

Ali ran all three configs on his ThinkPad before this went up (nixos-26.05, keyd 2.6.0, kanata 1.11.0). All three work as written. What he ran into along the way is noted in each section.

The three mappings

KeyTapped aloneHeld with another key
Caps LockEscapeControl
Left Shift(Shift
Right Shift)Shift

The tap window is 200 ms in every config below, the same value as TAP_MILLISEC: 200 in the original posts. The brackets are Shift+9 and Shift+0, which is where they sit on a US layout. On another layout, change the 9 and 0 to the keys that carry your brackets.

Run one of the three at a time. They all grab the keyboard device, so two of them enabled together will fight over it.

1. Interception Tools with dual-function-keys

This is the setup from the 2022 post, a little shorter. The NixOS module puts interception-tools and every package in plugins on the service’s path, so the job line can use the plain program names and does not need the ${pkgs...}/bin/ prefixes.

{ pkgs, ... }:
{
  services.interception-tools = {
    enable = true;
    plugins = [ pkgs.interception-tools-plugins.dual-function-keys ];
    udevmonConfig = ''
      - JOB: "intercept -g $DEVNODE | dual-function-keys -c /etc/dual-function-keys.yaml | uinput -d $DEVNODE"
        DEVICE:
          EVENTS:
            EV_KEY: [KEY_CAPSLOCK, KEY_LEFTSHIFT, KEY_RIGHTSHIFT]
    '';
  };

  environment.etc."dual-function-keys.yaml".text = ''
    TIMING:
      TAP_MILLISEC: 200
      DOUBLE_TAP_MILLISEC: 0

    MAPPINGS:
      - KEY: KEY_CAPSLOCK
        TAP: KEY_ESC
        HOLD: KEY_LEFTCTRL
      - KEY: KEY_LEFTSHIFT
        TAP: [KEY_LEFTSHIFT, KEY_9]
        HOLD: KEY_LEFTSHIFT
      - KEY: KEY_RIGHTSHIFT
        TAP: [KEY_RIGHTSHIFT, KEY_0]
        HOLD: KEY_RIGHTSHIFT
  '';
}

How it decides: release the key inside 200 ms with nothing else pressed and you get the tap. Press any other key in that window and the tap is cancelled, so a quick Ctrl+C still works. By default the hold key goes down as soon as you press, which means a tap on Caps Lock sends Control down and up before the Escape. If a program reacts to a lone Control, add HOLD_START: BEFORE_CONSUME to that mapping and only the tap key is sent.

Where it stands: the last tagged releases are dual-function-keys 1.5.0 (June 2022) and Interception Tools 0.6.8 (November 2021). It is finished software more than abandoned software, and the pipe design is still its strength. You can chain any plugin, or your own program, between intercept and uinput.

2. keyd

keyd is a single daemon with an INI style config. The NixOS module writes one file per entry under keyboards to /etc/keyd/.

{
  services.keyd = {
    enable = true;
    keyboards.default = {
      ids = [ "*" ];
      settings = {
        global = {
          overload_tap_timeout = 200;
        };
        main = {
          capslock = "overload(control, esc)";
          leftshift = "overload(shift, S-9)";
          rightshift = "overload(shift, S-0)";
        };
      };
    };
  };
}

overload(layer, action) turns the layer on while the key is held and runs the action on a tap. control and shift are layers that keyd defines for you, and S-9 means Shift+9.

One difference from dual-function-keys: overload has no timer of its own. Hold Caps Lock for two seconds, let go without touching another key, and you still get Escape. overload_tap_timeout = 200 brings back the 200 ms rule, so a long press that you abandon sends nothing.

ids = [ "*" ] matches every device keyd sees as a keyboard. On a ThinkPad that also means “ThinkPad Extra Buttons”, “Video Bus” and “Intel HID events”. The brightness and volume keys keep working, so it is harmless, but those names will show up in journalctl -u keyd. To leave one keyboard alone, add its id with a minus in front, for example "-0123:0456". sudo keyd monitor prints the id of whatever you type on (the module does not put keyd on your path, so add pkgs.keyd to your packages or run it from nix-shell -p keyd).

On a laptop there is one thing to know. keyd presents a single virtual keyboard, so libinput no longer knows the built-in keyboard is internal and stops pausing the trackpad while you type. The keyd README gives the fix, a libinput quirk, which on NixOS is:

{
  environment.etc."libinput/local-overrides.quirks".text = ''
    [Serial Keyboards]
    MatchUdevType=keyboard
    MatchName=keyd*keyboard
    AttrKeyboardIntegration=internal
  '';
}

The virtual device is named keyd virtual keyboard, so the MatchName line matches it, and with the quirk in place the trackpad pauses again while you type.

The journal also shows WARNING: failed to set effective group to "keyd" (make sure the group exists). The NixOS module does not create that group, and these mappings do not need it. The group is what lets a normal user talk to the daemon, which keyd uses for per-application layers with keyd-application-mapper.

Where it stands: the latest release is 2.6.0 (December 2025), and that is the version in nixos-26.05. Config errors do not stop the rebuild. They show up in journalctl -eu keyd.

3. kanata

kanata is written in Rust and its config is a Lisp style file. It can do far more than this (layers, chords, macros, home row mods), but three keys take five lines.

{
  services.kanata = {
    enable = true;
    keyboards.default = {
      extraDefCfg = "process-unmapped-keys yes";
      config = ''
        (defsrc)

        (deflayermap (base)
          caps (tap-hold-press 0 200 esc lctl)
          lsft (tap-hold-press 0 200 S-9 lsft)
          rsft (tap-hold-press 0 200 S-0 rsft))
      '';
    };
  };
}

tap-hold-press takes four values: the tap repress window, the hold timeout, the tap action and the hold action. With a hold timeout of 200, releasing inside 200 ms is a tap. The -press variant switches to the hold action as soon as another key goes down, which is the same rule dual-function-keys uses. The first value is 0 so that tapping and then holding does not repeat the tap key, the same as DOUBLE_TAP_MILLISEC: 0.

process-unmapped-keys yes matters here. Without it kanata only watches the keys it has a mapping for, and the early hold on the next key press does not fire.

With devices left out, kanata picks up every keyboard it finds. To bind one keyboard, set devices = [ "/dev/input/by-id/..." ];.

Two things I like about the NixOS module. It runs kanata --check on the generated file while building, so a typo fails nixos-rebuild and never reaches your running system. And it creates a separate service per keyboard, kanata-default in this case, so journalctl -eu kanata-default shows only that one.

One thing can go wrong on the first switch. The NixOS service runs kanata as an unprivileged dynamic user, and that user reaches /dev/uinput only through the uinput group. If something has already put an ACL on that device (Steam’s udev rule does, through uaccess), a nixos-rebuild switch can leave the group with no access. The config passes the check and the service then fails with:

[ERROR] Failed to open the output uinput device.
[ERROR] Permission denied (os error 13)

getfacl /dev/uinput shows group::--- when this is the cause. The fix is one line and a restart:

sudo setfacl -m g::rw /dev/uinput
sudo systemctl restart kanata-default

keyd and Interception Tools run as root and do not hit this.

Warning: keyboards plugged in later. Ali also ran kanata on a ThinkPad connected to a dock with an external keyboard, and that keyboard was not remapped until he restarted kanata-default. Unplugging and replugging it reproduced the problem. When a new device appears, kanata waits 200 ms and then tries to open it. On his machine udev took 0.7 to 1.1 seconds to give the input group access, so the unprivileged kanata service could not open the device, skipped it without a log line and never tried again. Adding extraArgs = [ "--wait-device-ms" "1500" ]; to the keyboard’s config only makes the wait longer, and kanata does not process keys while it waits. The code is the same in 1.11.0, 1.12.0 and current main (kanata#2255). Interception Tools and keyd do not have this problem, because they run as root. In Ali’s replug tests keyd picked the keyboard up about 0.1 seconds after the kernel created it, almost a second before udev changed the permissions. If you use a dock or switch keyboards often, choose one of those two.

One caveat from kanata’s own docs: on Linux, tap-hold keys can interact oddly with key repeat of the key pressed just before them. The workaround is in the guide under tap-hold, and most people never hit it with three keys.

Where it stands: the latest release is 1.12.0 (July 2026), the most recent of the three. nixos-26.05 ships 1.11.0, which is what the config above was run on, and 1.12.0 is in nixpkgs-unstable.

Resource use

Ali measured each tool on the same ThinkPad with systemctl show <unit> -p MemoryPeak,CPUUsageNSec and ps -o rss. The run lengths differ and the windows are short, so read these as rough numbers and not as a benchmark.

MemoryCPU timeMeasured after
Interception Tools + dual-function-keys10.1 MB peak5.7 sabout 28 hours
keyd 2.6.038 MB resident, 155 MB peak at startup0.25 s42 seconds
kanata 1.11.04 MB resident, 3 MB peak0.33 s6 minutes

All three sit idle between key presses, so CPU does not separate them. Memory does: keyd used about ten times as much as kanata.

Which one

dual-function-keyskeydkanata
Config for these three keysudevmon job plus a YAML file3 lines5 lines
200 ms tap rulebuilt inneeds overload_tap_timeoutbuilt in
Hold starts when another key is pressedyesyesyes, with tap-hold-press
Config checked at build time on NixOSnonoyes
Service runs as rootyesyesno, a dynamic user
Latest release1.5.0, June 20222.6.0, December 20251.12.0, July 2026 (1.11.0 in nixos-26.05)
Good atchaining small programsshort configs, per-application layerslarge layouts, home row mods

If the 2022 config is already in your configuration.nix and you are happy, there is no reason to move. If you are starting today and only want these three keys, keyd is the least to type. If you can see yourself adding layers or home row mods later, start with kanata, because you will not have to switch tools when you do.

After a rebuild, the test is the same for all three: tap Caps Lock in vim and you should leave insert mode, hold it and press C in a terminal and the running command should stop, tap each Shift and you should get ().

sudo nixos-rebuild switch