From 44c64fef16ed566786c8db276085b484c9d233f3 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 22 Jun 2017 03:22:48 +0200 Subject: [PATCH] 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 Cc: @lheckemann Fixes: #25526 --- nixos/modules/services/x11/xserver.nix | 37 ++++++++++---------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix index 09fcdd0b72b..01e1659b30b 100644 --- a/nixos/modules/services/x11/xserver.nix +++ b/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 + 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 <&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 = ''