nixos/xserver: add option to install custom xkb layouts
This commit is contained in:
parent
e21cb9933b
commit
171d5c9200
@ -811,6 +811,7 @@
|
|||||||
./services/web-servers/uwsgi.nix
|
./services/web-servers/uwsgi.nix
|
||||||
./services/web-servers/varnish/default.nix
|
./services/web-servers/varnish/default.nix
|
||||||
./services/web-servers/zope2.nix
|
./services/web-servers/zope2.nix
|
||||||
|
./services/x11/extra-layouts.nix
|
||||||
./services/x11/colord.nix
|
./services/x11/colord.nix
|
||||||
./services/x11/compton.nix
|
./services/x11/compton.nix
|
||||||
./services/x11/unclutter.nix
|
./services/x11/unclutter.nix
|
||||||
|
165
nixos/modules/services/x11/extra-layouts.nix
Normal file
165
nixos/modules/services/x11/extra-layouts.nix
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
layouts = config.services.xserver.extraLayouts;
|
||||||
|
|
||||||
|
layoutOpts = {
|
||||||
|
options = {
|
||||||
|
description = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "A short description of the layout.";
|
||||||
|
};
|
||||||
|
|
||||||
|
languages = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description =
|
||||||
|
''
|
||||||
|
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;
|
||||||
|
description = ''
|
||||||
|
The path to the xkb compat file.
|
||||||
|
This file sets the compatibility state, used to preserve
|
||||||
|
compatibility with xkb-unaware programs.
|
||||||
|
It must contain a <literal>xkb_compat "name" { ... }</literal> block.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
geometryFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
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.
|
||||||
|
It must contain a <literal>xkb_geometry "name" { ... }</literal> block.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
keycodesFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
The path to the xkb keycodes file.
|
||||||
|
This file specifies the range and the interpretation of the raw
|
||||||
|
keycodes sent by the keyboard.
|
||||||
|
It must contain a <literal>xkb_keycodes "name" { ... }</literal> block.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
symbolsFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
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
|
||||||
|
<literal>xkb_symbols "name" { ... }</literal> block.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
typesFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
The path to the xkb types file.
|
||||||
|
This file specifies the key types that can be associated with
|
||||||
|
the various keyboard keys.
|
||||||
|
It must contain a <literal>xkb_types "name" { ... }</literal> block.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
###### interface
|
||||||
|
|
||||||
|
options.services.xserver = {
|
||||||
|
extraLayouts = mkOption {
|
||||||
|
type = types.attrsOf (types.submodule layoutOpts);
|
||||||
|
default = {};
|
||||||
|
example = literalExample
|
||||||
|
''
|
||||||
|
{
|
||||||
|
mine = {
|
||||||
|
description = "My custom xkb layout.";
|
||||||
|
languages = [ "eng" ];
|
||||||
|
symbolsFile = /path/to/my/layout;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Extra custom layouts that will be included in the xkb configuration.
|
||||||
|
Information on how to create a new layout can be found here:
|
||||||
|
<link xlink:href="https://www.x.org/releases/current/doc/xorg-docs/input/XKB-Enhancing.html#Defining_New_Layouts"></link>.
|
||||||
|
For more examples see
|
||||||
|
<link xlink:href="https://wiki.archlinux.org/index.php/X_KeyBoard_extension#Basic_examples"></link>
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
config = mkIf (layouts != { }) {
|
||||||
|
|
||||||
|
# We don't override xkeyboard_config directly to
|
||||||
|
# reduce the amount of packages to be recompiled.
|
||||||
|
# Only the following packages are necessary to set
|
||||||
|
# a custom layout anyway:
|
||||||
|
nixpkgs.overlays = lib.singleton (self: super: {
|
||||||
|
|
||||||
|
xkb_patched = self.xorg.xkeyboardconfig_custom {
|
||||||
|
layouts = config.services.xserver.extraLayouts;
|
||||||
|
};
|
||||||
|
|
||||||
|
xorg = super.xorg // {
|
||||||
|
xorgserver = super.xorg.xorgserver.overrideAttrs (old: {
|
||||||
|
configureFlags = old.configureFlags ++ [
|
||||||
|
"--with-xkb-bin-directory=${self.xorg.xkbcomp}/bin"
|
||||||
|
"--with-xkb-path=${self.xkb_patched}/share/X11/xkb"
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
setxkbmap = super.xorg.setxkbmap.overrideAttrs (old: {
|
||||||
|
postInstall =
|
||||||
|
''
|
||||||
|
mkdir -p $out/share
|
||||||
|
ln -sfn ${self.xkb_patched}/etc/X11 $out/share/X11
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
|
||||||
|
xkbcomp = super.xorg.xkbcomp.overrideAttrs (old: {
|
||||||
|
configureFlags = "--with-xkb-config-root=${self.xkb_patched}/share/X11/xkb";
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
ckbcomp = super.ckbcomp.override {
|
||||||
|
xkeyboard_config = self.xkb_patched;
|
||||||
|
};
|
||||||
|
|
||||||
|
xkbvalidate = super.xkbvalidate.override {
|
||||||
|
libxkbcommon = self.libxkbcommon.override {
|
||||||
|
xkeyboard_config = self.xkb_patched;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
services.xserver.xkbDir = "${pkgs.xkb_patched}/etc/X11/xkb";
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
{ abiCompat ? null,
|
{ abiCompat ? null,
|
||||||
stdenv, makeWrapper, fetchurl, fetchpatch, buildPackages,
|
stdenv, makeWrapper, fetchurl, fetchpatch, buildPackages,
|
||||||
automake, autoconf, gettext, libiconv, libtool, intltool,
|
automake, autoconf, gettext, libiconv, libtool, intltool,
|
||||||
freetype, tradcpp, fontconfig, meson, ninja,
|
freetype, tradcpp, fontconfig, meson, ninja, ed,
|
||||||
libGL, spice-protocol, zlib, libGLU, dbus, libunwind, libdrm,
|
libGL, spice-protocol, zlib, libGLU, dbus, libunwind, libdrm,
|
||||||
mesa, udev, bootstrap_cmds, bison, flex, clangStdenv, autoreconfHook,
|
mesa, udev, bootstrap_cmds, bison, flex, clangStdenv, autoreconfHook,
|
||||||
mcpp, epoxy, openssl, pkgconfig, llvm_6,
|
mcpp, epoxy, openssl, pkgconfig, llvm_6,
|
||||||
@ -423,6 +423,85 @@ self: super:
|
|||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
# xkeyboardconfig variant extensible with custom layouts.
|
||||||
|
# See nixos/modules/services/x11/extra-layouts.nix
|
||||||
|
xkeyboardconfig_custom = { layouts ? { } }:
|
||||||
|
let
|
||||||
|
patchIn = name: layout:
|
||||||
|
with layout;
|
||||||
|
with lib;
|
||||||
|
''
|
||||||
|
# install layout files
|
||||||
|
${optionalString (compatFile != null) "cp '${compatFile}' 'compat/${name}'"}
|
||||||
|
${optionalString (geometryFile != null) "cp '${geometryFile}' 'geometry/${name}'"}
|
||||||
|
${optionalString (keycodesFile != null) "cp '${keycodesFile}' 'keycodes/${name}'"}
|
||||||
|
${optionalString (symbolsFile != null) "cp '${symbolsFile}' 'symbols/${name}'"}
|
||||||
|
${optionalString (typesFile != null) "cp '${typesFile}' 'types/${name}'"}
|
||||||
|
|
||||||
|
# patch makefiles
|
||||||
|
for type in compat geometry keycodes symbols types; do
|
||||||
|
if ! test -f "$type/${name}"; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
test "$type" = geometry && type_name=geom || type_name=$type
|
||||||
|
${ed}/bin/ed -v $type/Makefile.am <<EOF
|
||||||
|
/''${type_name}_DATA =
|
||||||
|
a
|
||||||
|
${name} \\
|
||||||
|
.
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
${ed}/bin/ed -v $type/Makefile.in <<EOF
|
||||||
|
/''${type_name}_DATA =
|
||||||
|
a
|
||||||
|
${name} \\
|
||||||
|
.
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
|
||||||
|
# add model description
|
||||||
|
${ed}/bin/ed -v rules/base.xml <<EOF
|
||||||
|
/<\/modelList>
|
||||||
|
-
|
||||||
|
a
|
||||||
|
<model>
|
||||||
|
<configItem>
|
||||||
|
<name>${name}</name>
|
||||||
|
<_description>${layout.description}</_description>
|
||||||
|
<vendor>${layout.description}</vendor>
|
||||||
|
</configItem>
|
||||||
|
</model>
|
||||||
|
.
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# add layout description
|
||||||
|
${ed}/bin/ed -v rules/base.xml <<EOF
|
||||||
|
/<\/layoutList>
|
||||||
|
-
|
||||||
|
a
|
||||||
|
<layout>
|
||||||
|
<configItem>
|
||||||
|
<name>${name}</name>
|
||||||
|
<_shortDescription>${name}</_shortDescription>
|
||||||
|
<_description>${layout.description}</_description>
|
||||||
|
<languageList>
|
||||||
|
${concatMapStrings (lang: "<iso639Id>${lang}</iso639Id>\n") layout.languages}
|
||||||
|
</languageList>
|
||||||
|
</configItem>
|
||||||
|
<variantList/>
|
||||||
|
</layout>
|
||||||
|
.
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
self.xkeyboardconfig.overrideAttrs (old: {
|
||||||
|
buildInputs = old.buildInputs ++ [ automake ];
|
||||||
|
postPatch = with lib; concatStrings (mapAttrsToList patchIn layouts);
|
||||||
|
});
|
||||||
|
|
||||||
xload = super.xload.overrideAttrs (attrs: {
|
xload = super.xload.overrideAttrs (attrs: {
|
||||||
nativeBuildInputs = attrs.nativeBuildInputs ++ [ gettext ];
|
nativeBuildInputs = attrs.nativeBuildInputs ++ [ gettext ];
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user