Skip to content
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

zsh: patch _setxkbmap completion script #46152

Merged
merged 1 commit into from Oct 19, 2018

Conversation

Ma27
Copy link
Member

@Ma27 Ma27 commented Sep 6, 2018

Instead of searching /usr it should search for the xkb dirs the
proper store path should be searched.

Fixes #46025

/cc @teto

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6/lib/zsh/5.6/zsh/zutil.so
shrinking /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6/bin/zsh
shrinking /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6/bin/zsh-5.6
gzipping man pages under /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6/share/man/
strip is /nix/store/h0lbngpv6ln56hjj59i6l77vxq25flbz-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6/lib  /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6/bin
patching script interpreter paths in /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6
/nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6/share/zsh/5.6/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/czx8vkrb9jdgjyz8qfksh10vrnqa723l-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6...
/nix/store/cq2b66s3iiav9irs99qild3dpkgwsz3q-zsh-5.6

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6/lib/zsh/5.6/zsh/rlimits.so
shrinking /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6/bin/zsh
shrinking /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6/bin/zsh-5.6
gzipping man pages under /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6/share/man/
strip is /nix/store/y4ymnvgxygpq05h03kyzbj572zmh6zla-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6/lib  /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6/bin
patching script interpreter paths in /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6
/nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6/share/zsh/5.6/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/fqm2x6kiay1q4vg7pqp4wp17bdijlyc3-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6...
/nix/store/q7srvvrnp777r2341pfxybw6hvl2vv8i-zsh-5.6

@matthewbauer
Copy link
Member

I'm not sure if we want to add setxkbmap to the closure. Maybe use /run/current-system/sw ?

@Ma27
Copy link
Member Author

Ma27 commented Sep 7, 2018

As stated in #46025 I'm not that happy about this either. However I doubt that /run/current-system is a better solution, especially since it breaks non-NixOS setups.
Do you know a better approach (e.g. extracting this into another wrapper)?

@Ma27
Copy link
Member Author

Ma27 commented Sep 14, 2018

@matthewbauer another idea I just had is to write a symlinkJoinwrapper for zsh which is activated when services.xserver and programs.zsh is enabled. In the end we need some (more-or-less) heuristic approach if we want to conditionally fix setxkbmap completions.

I'm absolutely not sure about this, it's possibly the easiest alternative to simply /run/current-system to get this working for NixOS users at least.

@matthewbauer
Copy link
Member

Does it need the full path to setxlbmap? Maybe we can just assume it’s on the path

@Ma27
Copy link
Member Author

Ma27 commented Sep 15, 2018

Yes, for now. environment.pathsToLink doesn't link /share/X11/ from inside a store path into /run/current-system, therefore specifying /run/current-system wouldn't solve the issue for setxkbmap completion.

And I'm not sure if I know of all possible consequences when linking these paths as well.

@michaelpj
Copy link
Contributor

Linking /share/X11 seems reasonable, perhaps the xserver module could do that? Then this could patch the script to look in XDG_DATA_DIRS, which seems more robust anyway.

@Ma27
Copy link
Member Author

Ma27 commented Sep 17, 2018

@michaelpj @matthewbauer would you mind having another look at this? :)

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2/lib/zsh/5.6.2/zsh/pcre.so
shrinking /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2/lib/zsh/5.6.2/zsh/system.so
shrinking /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2/lib/zsh/5.6.2/zsh/compctl.so
gzipping man pages under /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2/share/man/
strip is /nix/store/h0lbngpv6ln56hjj59i6l77vxq25flbz-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2/lib  /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2/bin
patching script interpreter paths in /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2
/nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2/share/zsh/5.6.2/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/czx8vkrb9jdgjyz8qfksh10vrnqa723l-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2...
/nix/store/gdpzicbsccraiqgfkcxwczc90jz44q0k-zsh-5.6.2

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2/lib/zsh/5.6.2/zsh/rlimits.so
shrinking /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2/bin/zsh
shrinking /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2/bin/zsh-5.6.2
gzipping man pages under /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2/share/man/
strip is /nix/store/y4ymnvgxygpq05h03kyzbj572zmh6zla-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2/lib  /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2/bin
patching script interpreter paths in /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2
/nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2/share/zsh/5.6.2/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/fqm2x6kiay1q4vg7pqp4wp17bdijlyc3-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2...
/nix/store/v5g4h0h9w10x8pjl95c7nifarl3xq6dc-zsh-5.6.2

Copy link
Contributor

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could you see if upstream might accept the patch?

- for dir in /usr/lib/X11/xkb /usr/share/X11/xkb; do
- if [ -d $dir ] ; then
- sourcedir=$dir
+ for dir in $(echo ${XDG_DATA_DIRS:gs/:/ /}); do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bash gibberish to me - I'm assuming you got this from someone else who traverses XDG_DATA_DIRS sensibly in bash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. The thing is, in bash IFS=":" would solve the problem. However this is zsh and I didn't manage to get this approach working, sorry :/
Do you have a better/cleaner idea? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea I'm afraid - surely there's someone else we can copy? I'm just aware that this sort of thing is easy to do wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just learned that IFS can be used in zsh if setopt sh_word_split is set. Do you prefer the current change over the original solution?
If so, file it upstream, but tomorrow, I need to catch some sleep now.

@Ma27
Copy link
Member Author

Ma27 commented Sep 17, 2018

LGTM. Could you see if upstream might accept the patch?

You're right. This patch isn't nixos-specific anymore. I'll consider filing it upstream when we have agreed on a solution on how to iterate over XDG_DATA_DIRS properly.

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2/lib/zsh/5.6.2/zsh/rlimits.so
shrinking /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2/bin/zsh
shrinking /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2/bin/zsh-5.6.2
gzipping man pages under /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2/share/man/
strip is /nix/store/y4ymnvgxygpq05h03kyzbj572zmh6zla-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2/lib  /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2/bin
patching script interpreter paths in /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2
/nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2/share/zsh/5.6.2/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/fqm2x6kiay1q4vg7pqp4wp17bdijlyc3-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2...
/nix/store/n8rnlymsvsqxg3ll1wpymg6hcza7715l-zsh-5.6.2

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2/lib/zsh/5.6.2/zsh/pcre.so
shrinking /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2/lib/zsh/5.6.2/zsh/system.so
shrinking /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2/lib/zsh/5.6.2/zsh/compctl.so
gzipping man pages under /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2/share/man/
strip is /nix/store/h0lbngpv6ln56hjj59i6l77vxq25flbz-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2/lib  /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2/bin
patching script interpreter paths in /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2
/nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2/share/zsh/5.6.2/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/czx8vkrb9jdgjyz8qfksh10vrnqa723l-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2...
/nix/store/nxjbamfxq2gw8gp352dszvnqcjs4n5qg-zsh-5.6.2

@michaelpj
Copy link
Contributor

LGTM (but I don't have merge rights)

@Ma27
Copy link
Member Author

Ma27 commented Sep 18, 2018

@michaelpj FYI, patched filed upstream: https://www.zsh.org/mla/workers/2018/msg01288.html

@matthewbauer thanks to the help of @michaelpj we have a better solution for the issue. What do you think about this? :)

Instead of searching `/usr` it should search for the `xkb`,
$XDG_DATA_DIRS will be searched. With this approach we allow compliance
on NixOS and non-NixOS systems to find `symbols` in the `xkb` directory.

The patch has been accepted by upstream, but isn't released yet, so this
is mainly a temporary fix until we can bump ZSH to the next stable version.

The `xserver` module links `/share/X11/xkb` to `/run/current-system` to
make this possible.

The fix can be tested inside the following VM:

```
{
  zshtest = {
    programs.zsh.enable = true;
    users.extraUsers.vm = {
      password = "vm";
      isNormalUser = true;
    };
    services.xserver.enable = true;
  };
}
```

Fixes NixOS#46025
@Ma27
Copy link
Member Author

Ma27 commented Sep 20, 2018

we now use fetchpatch to use the fix I submitted to upstream. This fixes the issue for now, we can drop this patch when bumping ZSH.

The pathsToLink change needs to stay though, otherwise /share/X11/xkb won't be in XDG_DATA_DIRS.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2/lib/zsh/5.6.2/zsh/pcre.so
shrinking /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2/lib/zsh/5.6.2/zsh/system.so
shrinking /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2/lib/zsh/5.6.2/zsh/compctl.so
gzipping man pages under /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2/share/man/
strip is /nix/store/h0lbngpv6ln56hjj59i6l77vxq25flbz-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2/lib  /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2/bin
patching script interpreter paths in /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2
/nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2/share/zsh/5.6.2/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/czx8vkrb9jdgjyz8qfksh10vrnqa723l-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2...
/nix/store/aaar10l4sx0hbmip7k5kk30acppzazq3-zsh-5.6.2

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: zsh

Partial log (click to expand)

shrinking /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2/lib/zsh/5.6.2/zsh/rlimits.so
shrinking /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2/bin/zsh
shrinking /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2/bin/zsh-5.6.2
gzipping man pages under /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2/share/man/
strip is /nix/store/y4ymnvgxygpq05h03kyzbj572zmh6zla-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2/lib  /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2/bin
patching script interpreter paths in /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2
/nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2/share/zsh/5.6.2/functions/harden: interpreter directive changed from "/bin/sh" to "/nix/store/fqm2x6kiay1q4vg7pqp4wp17bdijlyc3-bash-4.4-p23/bin/sh"
checking for references to /build in /nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2...
/nix/store/ypz1w8kmljk2x7p452kmmv2lxk3na3c5-zsh-5.6.2

@teto
Copy link
Member

teto commented Sep 20, 2018

as per #46764, you might want to add the patch to nixpkgs instead. btw, thanks for the diligent work on this issue :)

@Ma27
Copy link
Member Author

Ma27 commented Sep 20, 2018

I don't think that the issue applies here. This only happens when pulling a commit from a pull request which will be gone as soon as the branch is force-pushed. In this case the patch is already in zsh master and I don't think that they force-push their master branch ;)

@teto
Copy link
Member

teto commented Sep 20, 2018

right I got a bit hasty :shame:

@Ma27
Copy link
Member Author

Ma27 commented Oct 19, 2018

merging for now. This fixes an actual bug and the patch has been accepted by ZSH upstream, so in case of the next bump we may need to remove it, but this should work for now.

@Ma27 Ma27 merged commit e8fb77a into NixOS:master Oct 19, 2018
@Ma27 Ma27 deleted the fix-setxkbmap-completion branch October 19, 2018 12:33
@teto
Copy link
Member

teto commented Oct 19, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants