In nixos, how to remap caps lock to control

nixos

I followed the instructions at this email thread, and placed

services.xserver.xkbOptions = "grp:alt_space_toggle, ctrl:swapcaps";

in my /etc/nixos/configuration.nix file, but even after rebuilding with $ nixos-rebuild switch, and rebooting with nixos-rebuild boot and reboot, my caps lock key is not remapped.

How to map caps-lock to ctrl in nixos?

Best Answer

As you already tried, and as grwlf suggests, you can enable this in X11 by adding services.xserver.xkbOptions = "ctrl:swapcaps"; to /etc/nixos/configuration.nix.

To apply this setting in outside of X11, you can add console.useXkbConfig = true; to the configuration. This will apply the X keymap to the console keymap, which affects virtual consoles such as tty.

UPDATE: i18n.consoleUseXkbConfig was renamed to console.useXkbConfig in NixOS version 20.03