chisui / zsh-nix-shell

zsh plugin that lets you use zsh in nix-shell shells.
BSD 3-Clause "New" or "Revised" License
384 stars 19 forks source link

Doesn't work on Mac with zplug #3

Closed lovesegfault closed 6 years ago

lovesegfault commented 6 years ago

Adding this to zplug, when I try to nix-shell -p pkgconfig I get the following

$ nix-shell -p pkgconfig
/private/var/folders/m7/gts5k4696tq8m2k0hhgyyy640000gn/T/nix-shell-53907-0/rc: line 3: -e: command not found 
chisui commented 6 years ago

Could you share the mentioned file? It is generated by nix-shell each time you run it.

Please also include the output of nix-shell -p nix-info --run "nix-info -m" and zsh --version

lovesegfault commented 6 years ago
$ nix-shell -p nix-info --run "nix-info -m"
these paths will be fetched (0.01 MiB download, 0.03 MiB unpacked):
  /nix/store/05y0xx3q1d50b58hlrmg16cjdjyfnfvp-nix-info
  /nix/store/f56drlxcyirnskkwwzgzgjz6zqw7a03a-DarwinTools-1
copying path '/nix/store/f56drlxcyirnskkwwzgzgjz6zqw7a03a-DarwinTools-1' from 'https://cache.nixos.org'...
copying path '/nix/store/05y0xx3q1d50b58hlrmg16cjdjyfnfvp-nix-info' from 'https://cache.nixos.org'...
 - system: `"x86_64-darwin"`
 - host os: `Darwin 17.6.0, macOS 10.13.5`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.0.4`
 - channels(bemeurer): `""`
 - channels(root): `"nixpkgs-18.09pre142651.95a8cb3ade1"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
$ zsh --version
zsh 5.5.1 (x86_64-apple-darwin16.6.0)

And finally, the rc file that was mentioned

$ cat /private/var/folders/m7/gts5k4696tq8m2k0hHGYYy640000gn/T/nix-shell-78329-0/rc
[ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc; p=$PATH; dontAddDisableDepTrack=1; [ -e $stdenv/setup ] && source $stdenv/setup; PATH=$PATH:$p; unset p; set +e; [ -n "$PS1" ] && PS1='
\[\][nix-shell:\w]\$\[\] '; if [ "$(type -t runHook)" = function ]; then runHook shellHook; fi; unset NIX_ENFORCE_PURITY; unset NIX_INDENT_MAKE; shopt -u nullglob; unset TZ;
-e
zsh

Hope this helps!

chisui commented 6 years ago

Does this issue persist if you install the plugin as described in the readme?

edit: Yes it does.

chisui commented 6 years ago

I don't have access to a Mac. Could you check what is written if you run echo -e "\nzsh > out?

Could you also include an rc file that is generated if you run nix-shell without the plugin?

lovesegfault commented 6 years ago
$ echo -e "\nzsh" > out
$ cat out
zsh

How can I find the rc file ? Nix's hash-based naming is pretty useless to try and find the file by hand, and all the names in /private/var/folders are garbage :/

chisui commented 6 years ago

Ok, Thanks for the echo test. I really don't know how the -e got into the file. Do you know of any weird interactions with Macs version of bash that could cause this?

Run nix-shell -p nix-info --run "realpath \$0". Commands are appended to the rc file so this should print its location.

lovesegfault commented 6 years ago
$ nix-shell -p nix-info --run "realpath \$0"
/private/var/folders/m7/gts5k4696tq8m2k0hhgyyy640000gn/T/nix-shell-55166-0/rc
$ cat /private/var/folders/m7/gts5k4696tq8m2k0hhgyyy640000gn/T/nix-shell-55166-0/rc
[ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc; p=$PATH; dontAddDisableDepTrack=1; [ -e $stdenv/setup ] && source $stdenv/setup; PATH=$PATH:$p; unset p; set +e; [ -n "$PS1" ] && PS1='\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] '; if [ "$(type -t runHook)" = function ]; then runHook shellHook; fi; unset NIX_ENFORCE_PURITY; unset NIX_INDENT_MAKE; shopt -u nullglob; unset TZ; realpath $0
exit% 

I can't think of anything that would be causing that -e to show up in there, unfortunately. Seems really weird.

chisui commented 6 years ago

Sorry, I'm at a total loss here. I can't reproduce this issue on linux even by using the exact zsh version you are using. I also took a look at the Nix source that generates the rc file and couldn't find anything that would cause a rouge -e to be inserted. The only thing I can think of that might cause this issue is that the core commands like echo work differently.

I have added some echos to the buildShellShim to diagnose in what environment it actually is executed. Could install the plugin from branch issue-3 and run something like nix-shell -p nix-info --run "zsh --version" and share the output?

If anyone with anyone with access to a Mac reads this: Help on this issue is very welcome.

jyrimatti commented 6 years ago

It seems to be this -e from here https://github.com/chisui/zsh-nix-shell/blob/master/scripts/buildShellShim.zsh I don't know why, but maybe you could just remove it?

chisui commented 6 years ago

I reworked the shim so that echo doesn't use the -e flag. Could someone verify that this also works on Mac?

The code is in the shim-mac-fix branch.

The solution has to also work with the --command and --run arguments.

lovesegfault commented 6 years ago

I just tested this and it works!!

It does this weird thing where it echos rcfile after I do nix-shell; but it works. I tested --run and --command and they both worked as well, which the same echo behavior.

tty

chisui commented 6 years ago

yeah, I left in debug output. I will remove that before I merge the branch.

Does --run return to the parent console and does --command stay in the nix shell after the specified command is run?

lovesegfault commented 6 years ago

Yep, they both exactly as you've described, and do so flawlessly

chisui commented 6 years ago

Nice. Thanks for your help.