Browse Source

nixos/xserver: Improve checking keyboard layout

Enumerating the symbols directory doesn't include variants, so we're now
basically doing what "localectl list-x11-keymap-layouts" does but we use
sed instead.

The reason I'm not using localectl directly is because the path to
rules/base.lst is hardcoded in the systemd source.

Of course, the XKB specification allows for much more complicated rules,
but at least this should cover the most basic ones including variants.

So the sed expression itself is just for listing the available layouts
and variants and we use a grep with -xF to match only full lines without
interpreting regular expressions.

This should again allow to set "dvorak" as the layout option.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Cc: @lheckemann
Fixes: #25526
nsd-state-dir
aszlig 6 years ago
parent
commit
44c64fef16
No known key found for this signature in database GPG Key ID: 1DE8E48E57DB5436
  1. 47
      nixos/modules/services/x11/xserver.nix

47
nixos/modules/services/x11/xserver.nix

@ -648,34 +648,25 @@ in
services.xserver.xkbDir = mkDefault "${pkgs.xkeyboard_config}/etc/X11/xkb";
system.extraDependencies = [
(pkgs.runCommand "xkb-layouts-exist" {
layouts=cfg.layout;
} ''
missing=()
while read -d , layout
do
[[ -f "${cfg.xkbDir}/symbols/$layout" ]] || missing+=($layout)
done <<< "$layouts,"
if [[ ''${#missing[@]} -eq 0 ]]
then
touch $out
exit 0
fi
cat >&2 <<EOF
Some of the selected keyboard layouts do not exist:
''${missing[@]}
Set services.xserver.layout to the name of an existing keyboard
layout (check ${cfg.xkbDir}/symbols for options).
EOF
exit -1
'')
];
system.extraDependencies = singleton (pkgs.runCommand "xkb-layouts-exist" {
inherit (cfg) layout xkbDir;
} ''
sed -n -e ':i /^! \(layout\|variant\) *$/ {
:l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl
}' "$xkbDir/rules/base.lst" | grep -qxF "$layout" && exec touch "$out"
cat >&2 <<-EOF
The selected keyboard layout definition does not exist:
$layout
Set \`services.xserver.layout' to the name of an existing keyboard
layout (check $xkbDir/rules/base.lst for options).
EOF
exit 1
'');
services.xserver.config =
''

Loading…
Cancel
Save