Jump to content

Talk:Keyboard Layout Customization

From NixOS Wiki
Latest comment: 9 January 2023 by Itium in topic Key symbols reference broken

Key symbols reference broken

xorg.xproto seems not to exist anymore, so the command with nix-build --no-out-link '<nixpkgs>' -A xorg.xproto does not work anymore. Whats the correct replacement? --Itium (talk) 23:21, 9 January 2023 (UTC)Reply

Incomplete application of the keyboard layout across environments

The current page shows decent basic and advanced configuration, but it does not apply the desired keyboard layout consistently across all environments. I only use a basic keyboard configuration, so I cannot speak for the Advanced part; However, I can do so for the simple configuration.

For example, if one adds the following to their configuration.nix:

services.xserver.xkb = {
	layout = "fr";
	variant = "";
};

The keyboard layout is applied in most X11 environments, but not in the Linux Console (TTY) and not in certain Wayland compositors.

The solution to this seems pretty simple to me:

  • Add the console.useXkbConfig = true; option.
  • Export XKB_DEFAULT_* variables with environment.variables = {};, for example:
  • environment.variables = {
    	XKB_DEFAULT_LAYOUT = config.services.xserver.xkb.layout;
    	XKB_DEFAULT_VARIANT = config.services.xserver.xkb.variant;
    }
    

In my experience, this allows the Linux Console to use the keyboard settings set with services.xserver.xkb, and allows "misbehaving" Wayland compositors to do the same.

For example, this is my current /etc/nixos/input/keyboard-layout.nix module:

{ config, ... }: { # Keyboard layout settings. # To see a complete list of layouts, variants, and other settings: # • https://gist.github.com/jatcwang/ae3b7019f219b8cdc6798329108c9aee # # To see why this list cannot easily be seen within NixOS: # • https://github.com/NixOS/nixpkgs/issues/254523 # • https://github.com/NixOS/nixpkgs/issues/286283 services.xserver.xkb.layout = "us"; services.xserver.xkb.variant = "intl"; # Export the used keyboard layout. Some programs rely on this setting for it to be properly applied. environment.variables.XKB_DEFAULT_LAYOUT = config.services.xserver.xkb.layout; environment.variables.XKB_DEFAULT_VARIANT = config.services.xserver.xkb.variant; # Whether to let the virtual console's (TTY's) keyboard layout be the same as the one configured above. # If false, it needs to be manually configured with the `console.keyMap` option. console.useXkbConfig = true; }


On another note, there is the following line in this page:

«You can find valid values for these options in $(nix-build --no-out-link '<nixpkgs>' -A xkeyboard_config)/etc/X11/xkb/rules/base.lst», but this is incomplete, and also simply does not work. Removing this or fixing this would be great, though, I do not know how to do the latter.