Jump to content

Talk:Keyboard Layout Customization: Difference between revisions

From NixOS Wiki
Latest comment: 9 January 2023 by Itium in topic Key symbols reference broken
Atemo C (talk | contribs)
Atemo C (talk | contribs)
m Minor formatting tweaks (I somehow forgot that <syntaxhighlight lang="nix"> was a thing).
 
Line 9: Line 9:


For example, if one adds the following to their <b><code>configuration.nix</code></b>:
For example, if one adds the following to their <b><code>configuration.nix</code></b>:
<b><p style="white-space: pre-wrap; font-family: monospace; display: block; padding: 1rem; overflow-x: hidden; overflow-wrap: break-word; border: 1px solid">services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb <span style="color: #ff5c00;">=</span> <span style="color: #00a0ff;">{</span>
<syntaxhighlight lang="nix">
layout <span style="color: #ff5c00;">=</span> <span style="color: #e600ab">"fr"</span><span style="color: #ff5c00;">;</span>
services.xserver.xkb = {
variant <span style="color: #ff5c00;">=</span> <span style="color: #e600ab">""</span><span style="color: #ff5c00;">;</span>
layout = "fr";
<span style="color: #00a0ff;">}</span><span style="color: #ff5c00;">;</span>
variant = "";
</p></b>
};
</syntaxhighlight>
The keyboard layout is applied in most X11 environments, but not in the Linux Console (TTY) and not in certain Wayland compositors.
The keyboard layout is applied in most X11 environments, but not in the Linux Console (TTY) and not in certain Wayland compositors.


Line 20: Line 21:
<li> Add the <b><code>console<span style="color: #ff5c00;">.</span>useXkbConfig <span style="color: #ff5c00;">=</span> <span style="color: #ff0080;">true</span><span style="color: #ff5c00;">;</span></code></b> option.</li>
<li> Add the <b><code>console<span style="color: #ff5c00;">.</span>useXkbConfig <span style="color: #ff5c00;">=</span> <span style="color: #ff0080;">true</span><span style="color: #ff5c00;">;</span></code></b> option.</li>
<li> Export <b><code>XKB_DEFAULT_</code></b>* variables with <b><code>environment<span style="color: #ff5c00;">.</span>variables <span style="color: #ff5c00;">=</span> <span style="color: #00a0ff;">{}</span><span style="color: #ff5c00;">;</span></code></b>, for example:</li>
<li> Export <b><code>XKB_DEFAULT_</code></b>* variables with <b><code>environment<span style="color: #ff5c00;">.</span>variables <span style="color: #ff5c00;">=</span> <span style="color: #00a0ff;">{}</span><span style="color: #ff5c00;">;</span></code></b>, for example:</li>
<b><p style="white-space: pre-wrap; font-family: monospace; display: block; padding: 1rem; overflow-x: hidden; overflow-wrap: break-word; border: 1px solid">environment<span style="color: #ff5c00;">.</span>variables <span style="color: #ff5c00;">=</span> <span style="color: #00a0ff;">{</span>
<syntaxhighlight lang="nix">
XKB_DEFAULT_LAYOUT <span style="color: #ff5c00;">=</span> config<span style="color: #ff5c00;">.</span>services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span>layout<span style="color: #ff5c00;">;</span>
environment.variables = {
XKB_DEFAULT_VARIANT <span style="color: #ff5c00;">=</span> config<span style="color: #ff5c00;">.</span>services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span>variant<span style="color: #ff5c00;">;</span>
XKB_DEFAULT_LAYOUT = config.services.xserver.xkb.layout;
<span style="color: #00a0ff;">}</span><span style="color: #ff5c00;">;</span>
XKB_DEFAULT_VARIANT = config.services.xserver.xkb.variant;
</p></b>
}
</syntaxhighlight>
</ul>
</ul>


Line 30: Line 32:


For example, this is my current <b><code>/etc/nixos/input/keyboard-layout.nix</code></b> module:
For example, this is my current <b><code>/etc/nixos/input/keyboard-layout.nix</code></b> module:
<b><p style="white-space: pre-wrap; font-family: monospace; display: block; padding: 1rem; overflow-x: hidden; overflow-wrap: break-word; border: 1px solid"><span style="color: #00a0ff;">{</span> config<span style="color: #ff5c00;">, ...</span> <span style="color: #00a0ff;">}</span><span style="color: #ff5c00;">:</span> <span style="color: #00a0ff;">{</span>
<b><p style="white-space: pre-wrap; font-family: monospace; display: block; padding: 1rem; overflow-x: hidden; overflow-wrap: break-word; border: 1px solid; color: #dddddd; background-color: #1d1d24;"><span style="color: #00a0ff;">{</span> config<span style="color: #ff5c00;">, ...</span> <span style="color: #00a0ff;">}</span><span style="color: #ff5c00;">:</span> <span style="color: #00a0ff;">{</span>
<span style="color: #005cff"># Keyboard layout settings.
<span style="color: #0080ff"># Keyboard layout settings.
# To see a complete list of layouts, variants, and other settings:
# To see a complete list of layouts, variants, and other settings:
# • <code>https://gist.github.com/jatcwang/ae3b7019f219b8cdc6798329108c9aee</code>
# • <code style="background-color: #1d1d24; border-color: #333333;">https://gist.github.com/jatcwang/ae3b7019f219b8cdc6798329108c9aee</code>
#
#
# To see why this list cannot easily be seen within NixOS:
# To see why this list cannot easily be seen within NixOS:
# • <code>https://github.com/NixOS/nixpkgs/issues/254523</code>
# • <code style="background-color: #1d1d24; border-color: #333333;">https://github.com/NixOS/nixpkgs/issues/254523</code>
# • <code>https://github.com/NixOS/nixpkgs/issues/286283</code></span>
# • <code style="background-color: #1d1d24; border-color: #333333;">https://github.com/NixOS/nixpkgs/issues/286283</code></span>
services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span>layout <span style="color: #ff5c00;">=</span> <span style="color: #e600ab">"us"</span><span style="color: #ff5c00;">;</span>
services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span><span style="color: #ffc000;">layout</span> <span style="color: #ff5c00;">=</span> <span style="color: #e600ab">"us"</span><span style="color: #ff5c00;">;</span>
services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span>variant <span style="color: #ff5c00;">=</span> <span style="color: #e600ab">"intl"</span><span style="color: #ff5c00;">;</span>
services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span><span style="color: #ffc000;">variant</span> <span style="color: #ff5c00;">=</span> <span style="color: #e600ab">"intl"</span><span style="color: #ff5c00;">;</span>


<span style="color: #005cff"># Export the used keyboard layout. Some programs rely on this setting for it to be properly applied.</span>
<span style="color: #0080ff"># Export the used keyboard layout. Some programs rely on this setting for it to be properly applied.</span>
environment<span style="color: #ff5c00;">.</span>variables<span style="color: #ff5c00;">.</span>XKB_DEFAULT_LAYOUT <span style="color: #ff5c00;">=</span> config<span style="color: #ff5c00;">.</span>services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span>layout<span style="color: #ff5c00;">;</span>
environment<span style="color: #ff5c00;">.</span>variables<span style="color: #ff5c00;">.</span><span style="color: #ffc000;">XKB_DEFAULT_LAYOUT</span> <span style="color: #ff5c00;">=</span> config<span style="color: #ff5c00;">.</span>services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span><span style="color: #ffc000;">layout</span><span style="color: #ff5c00;">;</span>
environment<span style="color: #ff5c00;">.</span>variables<span style="color: #ff5c00;">.</span>XKB_DEFAULT_VARIANT <span style="color: #ff5c00;">=</span> config<span style="color: #ff5c00;">.</span>services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span>variant<span style="color: #ff5c00;">;</span>
environment<span style="color: #ff5c00;">.</span>variables<span style="color: #ff5c00;">.</span><span style="color: #ffc000;">XKB_DEFAULT_VARIANT</span> <span style="color: #ff5c00;">=</span> config<span style="color: #ff5c00;">.</span>services<span style="color: #ff5c00;">.</span>xserver<span style="color: #ff5c00;">.</span>xkb<span style="color: #ff5c00;">.</span><span style="color: #ffc000;">variant</span><span style="color: #ff5c00;">;</span>


<span style="color: #005cff"># Whether to let the virtual console's (TTY's) keyboard layout be the same as the one configured above.
<span style="color: #0080ff"># 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.</span>
# If false, it needs to be manually configured with the `console.keyMap` option.</span>
console<span style="color: #ff5c00;">.</span>useXkbConfig <span style="color: #ff5c00;">=</span> <span style="color: #ff0080;">true</span><span style="color: #ff5c00;">;</span>
console<span style="color: #ff5c00;">.</span><span style="color: #ffc000;">useXkbConfig</span> <span style="color: #ff5c00;">=</span> <span style="color: #ff0080;">true</span><span style="color: #ff5c00;">;</span>
<span style="color: #00a0ff;">}</span>
<span style="color: #00a0ff;">}</span>
</p></b>
</p></b>
Line 55: Line 57:
On another note, there is the following line in this page:
On another note, there is the following line in this page:


«<i>You can find valid values for these options in <b><code style="color: #00cc00;">$(nix-build --no-out-link '<nixpkgs>' -A xkeyboard_config)/etc/X11/xkb/rules/base.lst</code></b>»</i>, 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.
«<i>You can find valid values for these options in <b><code style="color: #00cc00; background-color: #000000;">$(nix-build --no-out-link '<nixpkgs>' -A xkeyboard_config)/etc/X11/xkb/rules/base.lst</code></b>»</i>, 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.
<!-- WHY did I write all of this by hand…? --!> ~~~~
<!-- WHY did I write all of this by hand…? No idea, but it looks neat.--!>

Latest revision as of 00:18, 4 September 2025

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.