git.iko.soy/typeable/nixpkgs
on master help sign in
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

commit44c64fef16ed566786c8db276085b484c9d233f3 authoraszlig <aszlig@redmoonstudios.org> dateThu 22 Jun 2017, 03:22 (9 years ago) parent7c0f6f4
1 file changed+19−28
nixos/modules/services/x11/xserver.nix+19−28
nixos/modules/services/x11/xserver.nix+19−28
@@ -648,34 +648,25 @@ in
648648
649649 services.xserver.xkbDir = mkDefault "${pkgs.xkeyboard_config}/etc/X11/xkb";
650650
651− system.extraDependencies = [
652− (pkgs.runCommand "xkb-layouts-exist" {
653− layouts=cfg.layout;
654− } ''
655− missing=()
656− while read -d , layout
657− do
658− [[ -f "${cfg.xkbDir}/symbols/$layout" ]] || missing+=($layout)
659− done <<< "$layouts,"
660− if [[ ''${#missing[@]} -eq 0 ]]
661− then
662− touch $out
663− exit 0
664− fi
665−
666− cat >&2 <<EOF
667−
668− Some of the selected keyboard layouts do not exist:
669−
670− ''${missing[@]}
671−
672− Set services.xserver.layout to the name of an existing keyboard
673− layout (check ${cfg.xkbDir}/symbols for options).
674−
675− EOF
676− exit -1
677− '')
678− ];
651+ system.extraDependencies = singleton (pkgs.runCommand "xkb-layouts-exist" {
652+ inherit (cfg) layout xkbDir;
653+ } ''
654+ sed -n -e ':i /^! \(layout\|variant\) *$/ {
655+ :l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl
656+ }' "$xkbDir/rules/base.lst" | grep -qxF "$layout" && exec touch "$out"
657+
658+ cat >&2 <<-EOF
659+
660+ The selected keyboard layout definition does not exist:
661+
662+ $layout
663+
664+ Set \`services.xserver.layout' to the name of an existing keyboard
665+ layout (check $xkbDir/rules/base.lst for options).
666+
667+ EOF
668+ exit 1
669+ '');
679670
680671 services.xserver.config =
681672 ''