services.xserver.xkb = {
model = "pc105";
layout = "us";
variant = "caps:swapescape";
};
console.useXkbConfig = true;
This config does not result in capslock and excape being swapped on the TTY. From what I’ve read so far, the last line should apply the xkb settings to the TTY, but it doesn’t. At least not the swapescape part, which is the only non-default setting anyway.
So how can I make this work?
In Arch I created a custom .map.gz, manually switched Esc and Capslock and put it in KEYMAP in /etc/vconsole.conf. I’d obviously prefer a less hands-on version in /etc/nixos/configuration.nix, but I could live with that solution.
IF I could figure out how to actually copy the .map.gz and edit vconsole.conf in a NixOS configuration. Which, so far, I couldn’t.
First day trying to setup NixOS, if it’s not already apparent from the question 
The console.keyMap option accepts an actual file as an argument, which will be given as the value of KEYMAP= in vconsole.conf. See nixpkgs/nixos/modules/config/console.nix at 8c816b3819c5b45e74d9f0268cffaaf86a038f56 · NixOS/nixpkgs · GitHub.
EDIT: Oh. You put the caps:swapescape in the variant option rather than options… that probably doesn’t work in X either… fix that, then see if the conversion works for you.
1 Like
For swapping out keys I prefer to modify the hwdb mappings: it’s a much more robust solution, almost as physically swapping the keys.
Here’s an example:
services.udev.extraHwdb = ''
evdev:name:AT Translated Set 2 keyboard:*
KEYBOARD_KEY_9d=rightmeta # rctrl -> super
KEYBOARD_KEY_3a=leftctrl # caps -> lctrl
KEYBOARD_KEY_1d=capslock # lctrl -> caps
'';
To find out the scan codes and key names you can use the evtest utility.
1 Like
Christ… Yes, the typo was the reason.
Just switching variant to options gave me the clean setup I was hoping for. That’s awesome.
Thank you very much =)
2 Likes