git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/xserver: Allow more than one keyboard layout

Regression introduced by 44c64fef16ed566786c8db276085b484c9d233f3. The services.xserver.layout option allows to specify more than one layout separated by comma, which the commit above didn't take into account. This is very similar to @lheckemann's pull request (#26984) but differs in the following ways: * Print out the full list available layouts (as suggested by @0xABAB in [1]). * Loop over $layout using the default IFS (and thus no need for escaping ${cfg.layout}), because the layouts won't contain white spaces. * Re-do the error message, which now uses multiple echos instead of a heredoc, so the line is wrapped according to the viewers terminal width. I've tested this with several good and bad layouts and also against the keymap NixOS VM subtests. [1]: https://github.com/NixOS/nixpkgs/pull/26984#discussion_r125146700 Signed-off-by: aszlig <aszlig@redmoonstudios.org> Fixes: #26961 Closes: #26984

commit69da1807f02daa776472893741c2f82eca8e838d authoraszlig <aszlig@redmoonstudios.org> dateMon 3 Jul 2017, 08:14 (9 years ago) parentd97cdfc
1 file changed+36−16
nixos/modules/services/x11/xserver.nix+36−16
nixos/modules/services/x11/xserver.nix+36−16
@@ -651,29 +651,49 @@ in
651651 system.extraDependencies = singleton (pkgs.runCommand "xkb-layouts-exist" {
652652 inherit (cfg) layout xkbDir;
653653 } ''
654− if sed -n -e ':i /^! \(layout\|variant\) *$/ {
654+ # We can use the default IFS here, because the layouts won't contain
655+ # spaces or tabs and are ruled out by the sed expression below.
656+ availableLayouts="$(
657+ sed -n -e ':i /^! \(layout\|variant\) *$/ {
655658 # Loop through all of the layouts/variants until we hit another ! at
656659 # the start of the line or the line is empty ('t' branches only if
657660 # the last substitution was successful, so if the line is empty the
658661 # substition will fail).
659662 :l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl
660− }' "$xkbDir/rules/base.lst" | grep -qxF "$layout"
661− then
662− touch "$out"
663− exit 0
664− fi
665−
666− cat >&2 <<-EOF
667−
668− The selected keyboard layout definition does not exist:
669−
670− $layout
663+ }' "$xkbDir/rules/base.lst" | sort -u
664+ )"
665+
666+ layoutNotFound() {
667+ echo >&2
668+ echo "The following layouts and variants are available:" >&2
669+ echo >&2
670+
671+ # While an output width of 80 is more desirable for small terminals, we
672+ # really don't know the amount of columns of the terminal from within
673+ # the builder. The content in $availableLayouts however is pretty
674+ # large, so let's opt for a larger width here, because it will print a
675+ # smaller amount of lines on modern KMS/framebuffer terminals and won't
676+ # lose information even in smaller terminals (it only will look a bit
677+ # ugly).
678+ echo "$availableLayouts" | ${pkgs.utillinux}/bin/column -c 150 >&2
679+
680+ echo >&2
681+ echo "However, the keyboard layout definition in" \
682+ "\`services.xserver.layout' contains the layout \`$1', which" \
683+ "isn't a valid layout or variant." >&2
684+ echo >&2
685+ exit 1
686+ }
671687
672− Set \`services.xserver.layout' to the name of an existing keyboard
673− layout (check $xkbDir/rules/base.lst for options).
688+ # Again, we don't need to take care of IFS, see the comment for
689+ # $availableLayouts.
690+ for l in ''${layout//,/ }; do
691+ if ! echo "$availableLayouts" | grep -qxF "$l"; then
692+ layoutNotFound "$l"
693+ fi
694+ done
674695
675− EOF
676− exit 1
696+ touch "$out"
677697 '');
678698
679699 services.xserver.config =