Keyboard Layout Customization: Difference between revisions

From NixOS Wiki
imported>Erikarvstedt
compile the layout to catch errors at build time and to improve x11 startup performance
imported>Erikarvstedt
mNo edit summary
Line 16: Line 16:
Lots of examples can be found in <code>$(nix-build --no-out-link '&lt;nixpkgs&gt;' -A xorg.xkeyboardconfig)/etc/X11/xkb/</code>. For available key symbols, see <code>$(nix-build --no-out-link '&lt;nixpkgs&gt;' -A xorg.xproto)/include/X11/keysymdef.h</code>.
Lots of examples can be found in <code>$(nix-build --no-out-link '&lt;nixpkgs&gt;' -A xorg.xkeyboardconfig)/etc/X11/xkb/</code>. For available key symbols, see <code>$(nix-build --no-out-link '&lt;nixpkgs&gt;' -A xorg.xproto)/include/X11/keysymdef.h</code>.


To load this file at the start of the X session, add this to your <code>configuration.nix</code>:
To load this file at the start of the X session, add the following to your <code>configuration.nix</code>. The extra compilation step <code>xkbcomp</code> helps catching layout errors at build time.


<source lang="nix">
<source lang="nix">

Revision as of 22:03, 3 March 2019

Simple

The easiest way to customize your keyboard layout on NixOS is with these options:

  • services.xserver.layout: Keyboard layout, or multiple keyboard layouts separated by commas.
  • services.xserver.xkbVariant: X keyboard variant
  • services.xserver.xkbModel: Keyboard model.
  • services.xserver.xkbOptions: X keyboard options; layout switching goes here.

You can find valid values for these options in $(nix-build --no-out-link '<nixpkgs>' -A xorg.xkeyboardconfig)/etc/X11/xkb/rules/base.lst

Advanced

If the above options aren't enough, you can instead create your own keyboard layout by going through xkb. To get started, install xorg.xkbcomp and run setxkbmap -print > layout.xkb to get an initial file. This corresponds to your current layout. Use xkbcomp layout.xkb $DISPLAY to load the file as your new layout. Refer to https://wiki.archlinux.org/index.php/X_KeyBoard_extension on how to edit this file.

Lots of examples can be found in $(nix-build --no-out-link '<nixpkgs>' -A xorg.xkeyboardconfig)/etc/X11/xkb/. For available key symbols, see $(nix-build --no-out-link '<nixpkgs>' -A xorg.xproto)/include/X11/keysymdef.h.

To load this file at the start of the X session, add the following to your configuration.nix. The extra compilation step xkbcomp helps catching layout errors at build time.

let
  compiledLayout = pkgs.runCommand "keyboard-layout" {} ''
    ${pkgs.xorg.xkbcomp}/bin/xkbcomp ${./path/to/layout.xkb} $out
  '';
in
  services.xserver.displayManager.sessionCommands = "${pkgs.xorg.xkbcomp}/bin/xkbcomp ${compiledLayout} $DISPLAY";

Relevant other options

  • services.xserver.exportConfiguration: Makes it so the above mentioned xkb directory (and the xorg.conf file) gets exported to /etc/X11/xkb, which is useful if you have to often look stuff up in it.
  • services.xserver.xkbDir: Allows you to set a different xkb directory altogether. All the above mentioned things will use this instead of the default one in regards to xkb stuff.
  • i18n.consoleUseXkbConfig: Makes it so the tty console has about the same layout as the one configured in the services.xserver options.

Configs