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
This commit is contained in:
aszlig 2017-06-22 03:22:48 +02:00
parent 7c0f6f4be5
commit 44c64fef16
No known key found for this signature in database
GPG Key ID: 1DE8E48E57DB5436

View File

@ -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
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
cat >&2 <<-EOF
Some of the selected keyboard layouts do not exist:
The selected keyboard layout definition does not exist:
''${missing[@]}
$layout
Set services.xserver.layout to the name of an existing keyboard
layout (check ${cfg.xkbDir}/symbols for options).
Set \`services.xserver.layout' to the name of an existing keyboard
layout (check $xkbDir/rules/base.lst for options).
EOF
exit -1
'')
];
EOF
exit 1
'');
services.xserver.config =
''