[solved] Custom keyboard in GNOME - link `xkeyboard-config` to .config/xdg

I’m trying to use custom keyboard layout in GNOME with Wayland. My current setup is:

  # Configure keymap in X11
  services.xserver = {
    layout = "fck";
    extraLayouts.fck = {
      description = "Fancy czech keyboard";
      languages = [ "eng" "cs" ];
      symbolsFile = builtins.fetchurl {
        url = "https://gitlab.com/JanKaifer/fck/-/raw/master/cz";

Gnome is not picking this up (I can’t select it in the settings), but I can select this layout when using X11 by doing setxkbmap, but there is no way to do it in Wayland.

There are many posts regarding this, but none of them helped me. The most relevant was this:

The fix itself mentions this PR in GNOME:

This PR says that GNOME is looking for keyboard layouts here: “$XDG_CONFIG_ROOT/xkb” this evaluates to “.config/xkb” on my machine.
When I tried looking for the layout that is generated by nix I got few packages in /nix/store with echo /**/xkb/symbols/fck.

So I tried symlinking it to ~/.config. Something like ~/.config/xkb -> /nix/store/1jb6zf1x7xkcv0p3nfnprqhh32vhkrmn-xkeyboard-config-2.33/etc/X11/xkb/.
This worked and I can see my layout in the settings.
Now I need to generate that nix store path programmatically in my config.

I tried pkgs.xkeyboard_config.outPath, but that gives me a path to a different package that doesn’t have my custom layout.

One dirty hack is that once I add the layout in settings (via hardcoded path to /nix/store) GNOME remembers that layout forever. I can remove that link to my /nix/store and it will continue to work.

Did I solve it? Maybe? Hopefully!

I had XDG_CONFIG_HOME = "$HOME/.config" in my configuration.nix.
When I removed that line it started working again. It also cleared XDG_CONFIG_ROOT.

Weird, but I don’t need those variables (those are just leftovers from my old system) so I will accept this as a solution.

One way to do this is simply to call your layout custom. I’m not sure which package it is, but there is a package that contains a database of keyboard layouts that has a special entry for us to use like that. It should show up in GNOME.

1 Like

That is not a thing, the variable is named XKB_CONFIG_ROOT, which the extra-layouts module creates by default:

An it should contain a value like /nix/store/01qsglilnjzlczknw9zvh0gmf6h2slcp-xkeyboard-config-2.33/etc/X11/xkb.

~/.config sounds like you are confusing the variable with XDG_CONFIG_HOME (notice the prefix is named after X KeyBoard, not X Desktop Group, and the suffix is root, not home).

I would expect it to work unless there was a regression. Though it probably requires you to re-log in after you rebuild your system since it is not possible to change environment of running programs in general.

As I mentioned, the extra-layouts module already sets the variable, which is then picked up by libxkb & co.

1 Like

:man_facepalming: I totally missed the XDG vs XKB difference.
But weirdly adding and removing “XDG_CONFIG_HOME” from my configuration.nix was adding/removing the layout from the settings.

But I tested XKB_CONFIG_ROOT and it points to the correct /nix/store/ path.

Thanks a lot for catching this obvious mistake, I was struggling with this for a few hours.