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