2018-10-03 14:08:34 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
layouts = config.services.xserver.extraLayouts;
|
|
|
|
|
|
|
|
layoutOpts = {
|
|
|
|
options = {
|
|
|
|
description = mkOption {
|
|
|
|
type = types.str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "A short description of the layout.";
|
2018-10-03 14:08:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
languages = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description =
|
2022-07-28 21:19:15 +00:00
|
|
|
lib.mdDoc ''
|
2018-10-03 14:08:34 +00:00
|
|
|
A list of languages provided by the layout.
|
|
|
|
(Use ISO 639-2 codes, for example: "eng" for english)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
compatFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-10-03 14:08:34 +00:00
|
|
|
The path to the xkb compat file.
|
|
|
|
This file sets the compatibility state, used to preserve
|
|
|
|
compatibility with xkb-unaware programs.
|
2022-07-28 21:19:15 +00:00
|
|
|
It must contain a `xkb_compat "name" { ... }` block.
|
2018-10-03 14:08:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
geometryFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-10-03 14:08:34 +00:00
|
|
|
The path to the xkb geometry file.
|
|
|
|
This (completely optional) file describes the physical layout of
|
|
|
|
keyboard, which maybe be used by programs to depict it.
|
2022-07-28 21:19:15 +00:00
|
|
|
It must contain a `xkb_geometry "name" { ... }` block.
|
2018-10-03 14:08:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
keycodesFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-10-03 14:08:34 +00:00
|
|
|
The path to the xkb keycodes file.
|
|
|
|
This file specifies the range and the interpretation of the raw
|
|
|
|
keycodes sent by the keyboard.
|
2022-07-28 21:19:15 +00:00
|
|
|
It must contain a `xkb_keycodes "name" { ... }` block.
|
2018-10-03 14:08:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
symbolsFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-10-03 14:08:34 +00:00
|
|
|
The path to the xkb symbols file.
|
|
|
|
This is the most important file: it defines which symbol or action
|
|
|
|
maps to each key and must contain a
|
2022-07-28 21:19:15 +00:00
|
|
|
`xkb_symbols "name" { ... }` block.
|
2018-10-03 14:08:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
typesFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-10-03 14:08:34 +00:00
|
|
|
The path to the xkb types file.
|
|
|
|
This file specifies the key types that can be associated with
|
|
|
|
the various keyboard keys.
|
2022-07-28 21:19:15 +00:00
|
|
|
It must contain a `xkb_types "name" { ... }` block.
|
2018-10-03 14:08:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-09-16 23:39:38 +00:00
|
|
|
xkb_patched = pkgs.xorg.xkeyboardconfig_custom {
|
|
|
|
layouts = config.services.xserver.extraLayouts;
|
|
|
|
};
|
|
|
|
|
2018-10-03 14:08:34 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.xserver = {
|
|
|
|
extraLayouts = mkOption {
|
|
|
|
type = types.attrsOf (types.submodule layoutOpts);
|
|
|
|
default = {};
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression
|
2018-10-03 14:08:34 +00:00
|
|
|
''
|
|
|
|
{
|
|
|
|
mine = {
|
|
|
|
description = "My custom xkb layout.";
|
|
|
|
languages = [ "eng" ];
|
|
|
|
symbolsFile = /path/to/my/layout;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-10-03 14:08:34 +00:00
|
|
|
Extra custom layouts that will be included in the xkb configuration.
|
|
|
|
Information on how to create a new layout can be found here:
|
2022-07-28 21:19:15 +00:00
|
|
|
[](https://www.x.org/releases/current/doc/xorg-docs/input/XKB-Enhancing.html#Defining_New_Layouts).
|
2018-10-03 14:08:34 +00:00
|
|
|
For more examples see
|
2022-07-28 21:19:15 +00:00
|
|
|
[](https://wiki.archlinux.org/index.php/X_KeyBoard_extension#Basic_examples)
|
2018-10-03 14:08:34 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf (layouts != { }) {
|
|
|
|
|
2019-12-20 21:52:53 +00:00
|
|
|
environment.sessionVariables = {
|
|
|
|
# runtime override supported by multiple libraries e. g. libxkbcommon
|
|
|
|
# https://xkbcommon.org/doc/current/group__include-path.html
|
2021-09-16 23:39:38 +00:00
|
|
|
XKB_CONFIG_ROOT = "${xkb_patched}/etc/X11/xkb";
|
2019-12-20 21:52:53 +00:00
|
|
|
};
|
|
|
|
|
2019-09-08 12:51:23 +00:00
|
|
|
services.xserver = {
|
2021-09-16 23:39:38 +00:00
|
|
|
xkbDir = "${xkb_patched}/etc/X11/xkb";
|
2021-09-07 22:57:37 +00:00
|
|
|
exportConfiguration = config.services.xserver.displayManager.startx.enable
|
|
|
|
|| config.services.xserver.displayManager.sx.enable;
|
2019-09-08 12:51:23 +00:00
|
|
|
};
|
2018-10-03 14:08:34 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|