Keyboard Layout Customization: Difference between revisions
imported>Timstott m Update xkeyboardconfig attribute name |
imported>Qknight No edit summary |
||
| Line 1: | Line 1: | ||
== Simple == | == Using xkbcomp == | ||
=== Simple === | |||
The easiest way to customize your keyboard layout on NixOS is with these options: | The easiest way to customize your keyboard layout on NixOS is with these options: | ||
| Line 10: | Line 12: | ||
You can find valid values for these options in <code>$(nix-build --no-out-link '<nixpkgs>' -A xkeyboard_config)/etc/X11/xkb/rules/base.lst</code> | You can find valid values for these options in <code>$(nix-build --no-out-link '<nixpkgs>' -A xkeyboard_config)/etc/X11/xkb/rules/base.lst</code> | ||
== Advanced == | === Advanced === | ||
If the above options aren't enough, you can instead create your own keyboard layout by going through xkb. To get started, install <code>xorg.xkbcomp</code> and run <code>setxkbmap -print > layout.xkb</code> to get an initial file. This corresponds to your current layout. Use <code>xkbcomp layout.xkb $DISPLAY</code> 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. | If the above options aren't enough, you can instead create your own keyboard layout by going through xkb. To get started, install <code>xorg.xkbcomp</code> and run <code>setxkbmap -print > layout.xkb</code> to get an initial file. This corresponds to your current layout. Use <code>xkbcomp layout.xkb $DISPLAY</code> 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. | ||
| Line 26: | Line 28: | ||
services.xserver.displayManager.sessionCommands = "${pkgs.xorg.xkbcomp}/bin/xkbcomp ${compiledLayout} $DISPLAY"; | services.xserver.displayManager.sessionCommands = "${pkgs.xorg.xkbcomp}/bin/xkbcomp ${compiledLayout} $DISPLAY"; | ||
</source> | </source> | ||
== Relevant other options == | === Relevant other options === | ||
* <code>services.xserver.exportConfiguration</code>: Makes it so the above mentioned xkb directory (and the <code>xorg.conf</code> file) gets exported to <code>/etc/X11/xkb</code>, which is useful if you have to often look stuff up in it. | * <code>services.xserver.exportConfiguration</code>: Makes it so the above mentioned xkb directory (and the <code>xorg.conf</code> file) gets exported to <code>/etc/X11/xkb</code>, which is useful if you have to often look stuff up in it. | ||
| Line 32: | Line 34: | ||
* <code>i18n.consoleUseXkbConfig</code>: Makes it so the tty console has about the same layout as the one configured in the <code>services.xserver</code> options. | * <code>i18n.consoleUseXkbConfig</code>: Makes it so the tty console has about the same layout as the one configured in the <code>services.xserver</code> options. | ||
== Configs == | === Configs === | ||
* https://github.com/Infinisil/system/blob/master/config/new-modules/keylayout.nix | * https://github.com/Infinisil/system/blob/master/config/new-modules/keylayout.nix | ||
== Using xmodmap == | |||
Since it is much simpler to use xmodmap and also because I couldn|t get the xkbcomp way to work on my NixOS machine I decided to keep using xmodmap: | |||
<source lang="nix"> | |||
cat /etc/nixos/configuration.nix | |||
... | |||
let | |||
myCustomLayout = pkgs.writeText "xkb-layout" '' | |||
! Map umlauts to RIGHT ALT + <key> | |||
keycode 108 = Mode_switch | |||
keysym e = e E EuroSign | |||
keysym c = c C cent | |||
keysym a = a A adiaeresis Adiaeresis | |||
keysym o = o O odiaeresis Odiaeresis | |||
keysym u = u U udiaeresis Udiaeresis | |||
keysym s = s S ssharp | |||
! disable capslock | |||
! remove Lock = Caps_Lock | |||
''; | |||
in | |||
... | |||
services.xserver.displayManager.sessionCommands = "${pkgs.xorg.xmodmap}/bin/xmodmap ${myCustomLayout}"; | |||
</source> | |||
Works after boot and after suspend/resume. | |||