@@ -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 =