-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xserver: check case of multiple keyboard layouts #26984
Conversation
@lheckemann, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @aszlig and @nbp to be potential reviewers. |
cc @aszlig |
missing=() | ||
for layout in "''${layouts[@]}" ; do | ||
if ! sed -n -e ':i /^! \(layout\|variant\) *$/ { | ||
:l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holy Batman for your sed invocation. I doubt many people would be able to read that without consulting a manual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not mine, @aszlig's. It seems to work so I just left it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xABAB: Although I think the expression is quite simple (if you know sed), I'm going to add a comment with a description anyway.
for layout in "''${layouts[@]}" ; do | ||
if ! sed -n -e ':i /^! \(layout\|variant\) *$/ { | ||
:l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl | ||
}' "$xkbDir/rules/base.lst" | grep -qxF "$layout" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be safer to add --
to stop processing options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would result in it searching the file named by "$layout"
. But in a similar vein, I should add -e
.
cat >&2 <<-EOF | ||
|
||
The selected keyboard layout definition does not exist: | ||
The selected keyboard layout definitions do not exist: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good that you are trying to help the user, but you could also just output all the valid values (a constructive reply from the machine) with the file name, instead of letting the machine say that the user messed up without any help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too many valid values for printing all of them to be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think we can do that if we pipe them into column
.
|
||
EOF | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened to this exit 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't necessary, the build will fail because it didn't produce $out
. I suppose it's better to have it explicit rather than implicit though, so I'll put it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel many of my concerns need to be addressed.
}' "$xkbDir/rules/base.lst" | grep -qxF "$layout" | ||
then | ||
touch "$out" | ||
IFS=, read -a layouts <<<'${cfg.layout}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not well escaped, because if the layout
option contains a single quote you can inject arbitrary shell commands, like let's say layout = "' || exit 0
. In this case it's better to use $layout
here, because we already have that in the builder environment.
missing=() | ||
for layout in "''${layouts[@]}" ; do | ||
if ! sed -n -e ':i /^! \(layout\|variant\) *$/ { | ||
:l; n; /^!/bi; s/^ *\([^ ]\+\).*/\1/p; tl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xABAB: Although I think the expression is quite simple (if you know sed), I'm going to add a comment with a description anyway.
cat >&2 <<-EOF | ||
|
||
The selected keyboard layout definition does not exist: | ||
The selected keyboard layout definitions do not exist: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think we can do that if we pipe them into column
.
layout (check $xkbDir/rules/base.lst for options). | ||
Set \`services.xserver.layout' to include only names of | ||
existing keyboard layouts (check $xkbDir/rules/base.lst | ||
for options). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should just use echo here, so the lines wrap around the actual line width of the users terminal, because $xkbDir
clearly stands out in length here and might be confusing if you just glimpse over it.
I'm going to commit a different fix of #26961 which is similar to your PR, but with the comments addressed. Basically I was the one who broke it, so I'll fix it :-D |
Alright. |
This was brought up by @0xABAB in #26984 by the following comment: #26984 (comment) Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Regression introduced by 44c64fe. 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]: #26984 (comment) Signed-off-by: aszlig <aszlig@redmoonstudios.org> Fixes: #26961 Closes: #26984
This was brought up by @0xABAB in NixOS#26984 by the following comment: NixOS#26984 (comment) Signed-off-by: aszlig <aszlig@redmoonstudios.org> (cherry picked from commit d97cdfc)
Regression introduced by 44c64fe. 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 (NixOS#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]: NixOS#26984 (comment) Signed-off-by: aszlig <aszlig@redmoonstudios.org> Fixes: NixOS#26961 Closes: NixOS#26984 (cherry picked from commit 69da180)
Motivation for this change
#26961
Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)