at 24.11-pre 4.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 layouts = config.services.xserver.xkb.extraLayouts; 7 8 layoutOpts = { 9 options = { 10 description = mkOption { 11 type = types.str; 12 description = "A short description of the layout."; 13 }; 14 15 languages = mkOption { 16 type = types.listOf types.str; 17 description = '' 18 A list of languages provided by the layout. 19 (Use ISO 639-2 codes, for example: "eng" for english) 20 ''; 21 }; 22 23 compatFile = mkOption { 24 type = types.nullOr types.path; 25 default = null; 26 description = '' 27 The path to the xkb compat file. 28 This file sets the compatibility state, used to preserve 29 compatibility with xkb-unaware programs. 30 It must contain a `xkb_compat "name" { ... }` block. 31 ''; 32 }; 33 34 geometryFile = mkOption { 35 type = types.nullOr types.path; 36 default = null; 37 description = '' 38 The path to the xkb geometry file. 39 This (completely optional) file describes the physical layout of 40 keyboard, which maybe be used by programs to depict it. 41 It must contain a `xkb_geometry "name" { ... }` block. 42 ''; 43 }; 44 45 keycodesFile = mkOption { 46 type = types.nullOr types.path; 47 default = null; 48 description = '' 49 The path to the xkb keycodes file. 50 This file specifies the range and the interpretation of the raw 51 keycodes sent by the keyboard. 52 It must contain a `xkb_keycodes "name" { ... }` block. 53 ''; 54 }; 55 56 symbolsFile = mkOption { 57 type = types.nullOr types.path; 58 default = null; 59 description = '' 60 The path to the xkb symbols file. 61 This is the most important file: it defines which symbol or action 62 maps to each key and must contain a 63 `xkb_symbols "name" { ... }` block. 64 ''; 65 }; 66 67 typesFile = mkOption { 68 type = types.nullOr types.path; 69 default = null; 70 description = '' 71 The path to the xkb types file. 72 This file specifies the key types that can be associated with 73 the various keyboard keys. 74 It must contain a `xkb_types "name" { ... }` block. 75 ''; 76 }; 77 78 }; 79 }; 80 81 xkb_patched = pkgs.xorg.xkeyboardconfig_custom { 82 layouts = config.services.xserver.xkb.extraLayouts; 83 }; 84 85in 86 87{ 88 89 imports = [ 90 (lib.mkRenamedOptionModuleWith { 91 sinceRelease = 2311; 92 from = [ "services" "xserver" "extraLayouts" ]; 93 to = [ "services" "xserver" "xkb" "extraLayouts" ]; 94 }) 95 ]; 96 97 ###### interface 98 99 options.services.xserver.xkb = { 100 extraLayouts = mkOption { 101 type = types.attrsOf (types.submodule layoutOpts); 102 default = { }; 103 example = literalExpression 104 '' 105 { 106 mine = { 107 description = "My custom xkb layout."; 108 languages = [ "eng" ]; 109 symbolsFile = /path/to/my/layout; 110 }; 111 } 112 ''; 113 description = '' 114 Extra custom layouts that will be included in the xkb configuration. 115 Information on how to create a new layout can be found here: 116 <https://www.x.org/releases/current/doc/xorg-docs/input/XKB-Enhancing.html#Defining_New_Layouts>. 117 For more examples see 118 <https://wiki.archlinux.org/index.php/X_KeyBoard_extension#Basic_examples> 119 ''; 120 }; 121 122 }; 123 124 ###### implementation 125 126 config = mkIf (layouts != { }) { 127 128 environment.sessionVariables = { 129 # runtime override supported by multiple libraries e. g. libxkbcommon 130 # https://xkbcommon.org/doc/current/group__include-path.html 131 XKB_CONFIG_ROOT = config.services.xserver.xkb.dir; 132 }; 133 134 services.xserver = { 135 xkb.dir = "${xkb_patched}/etc/X11/xkb"; 136 exportConfiguration = config.services.xserver.displayManager.startx.enable 137 || config.services.xserver.displayManager.sx.enable; 138 }; 139 140 }; 141 142}