chisui / zsh-nix-shell

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

setup-hook: bad substitution #14

Open chuwy opened 4 years ago

chuwy commented 4 years ago

Issue description

I'm getting the following error when trying to run nix-shell with zsh-nix-shell enabled:

/nix/store/6wvhspx58ak4yy3limaf1fb32792l187-cctools-binutils-darwin-wrapper-927.0.2/nix-support/setup-hook: line 138: ${role_pre}${cmd^^}=${cmd}: bad substitution

If I comment zsh-nix-shell out - it works fine. I thought it might be related to https://github.com/NixOS/nixpkgs/issues/71625, but I have same old default bash-3.2 from Mojave and didn't have to update it with brew.

I used plain installation (I use prezto instead of Oh-My-ZSH).

Steps to reproduce

I have a following default.nix file:

let pkgs = import <nixpkgs> {};
in
pkgs.stdenv.mkDerivation rec {
  name = "rust";
  buildInputs = [ pkgs.rustup ];
}

Technical details

$ command nix-shell -p nix-info --run "nix-info -m"
...
 - system: `"x86_64-darwin"`
 - host os: `Darwin 18.7.0, macOS 10.14.6`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.1`
 - channels(antonparkhomenko): `"nixpkgs-20.03pre205792.fb1bc1b891f"`
 - nixpkgs: `/Users/antonparkhomenko/.nix-defexpr/channels/nixpkgs`
$ zsh --version  # installed by nix
zsh 5.7.1 (x86_64-apple-darwin17.7.0)
$ /bin/zsh --version
zsh 5.3 (x86_64-apple-darwin18.0)
chuwy commented 4 years ago

It seems that problem went away after nix-env -i bash

chisui commented 4 years ago

when calling nix-shell in the bash provided MacOS you get a shell that is provided by nix:

$ nix-shell -p hello --run "where bash"
/nix/store/<hash>-bash-interactive-4.4-p23/bin/bash

but the plugins build-shell-shim uses /bin/bash. I'm not sure how I would get that shell without building the plugin with nix.

For now I will update the Readme.

mark-pictor-csec commented 1 year ago

On MacOS you have to have a bash with version 4 or greater. https://github.com/chisui/zsh-nix-shell/issues/14

it appears that brew's bash isn't good enough either (though I'm getting a slightly different error, ... command not found):

$ which -a bash
/usr/local/bin/bash
/bin/bash
$ bash --version
GNU bash, version 5.2.2(1)-release (x86_64-apple-darwin21.6.0)
#...
$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin22)
#...
$ nix-shell --command 'sed "s/\033/ESC/g" < /private/tmp/nix-shell-*/rc;echo;echo' -p cowsay
_nix_shell_clean_tmpdir() { command rm -rf '/private/tmp/nix-shell-48073-0'; }; trap _nix_shell_clean_tmpdir EXIT; exitHooks+=(_nix_shell_clean_tmpdir); failureHooks+=(_nix_shell_clean_tmpdir); [ -n "$PS1" ] && [ -e ~/.bashrc ] && source ~/.bashrc;p=$PATH; unset PATH;dontAddDisableDepTrack=1; [ -e $stdenv/setup ] && source $stdenv/setup; PATH=$PATH:$p; unset p; PATH='/path/to/zsh-nix-shell/scripts':"$PATH"; SHELL='/path/to/zsh-nix-shell/scripts/buildShellShim'; BASH='/path/to/zsh-nix-shell/scripts/buildShellShim'; set +e; [ -n "$PS1" -a -z "$NIX_SHELL_PRESERVE_PROMPT" ] && PS1='
\[ESC[1;32m\][nix-shell:\w]\$\[ESC[0m\] '; if [ "$(type -t runHook)" = function ]; then runHook shellHook; fi; unset NIX_ENFORCE_PURITY; shopt -u nullglob; unset TZ; shopt -s execfail;sed "s/ESC/ESC/g" < /private/tmp/nix-shell-48073-0/rc
SHELL=
unset NIX_BUILD_SHELL
FPATH=$(echo 'echo $FPATH' |  --stdin)
for path in ${PATH//:/ }; do
  if [[ $path = /nix/store/* ]]; then
    path=${path/%bin/share\/zsh\/site-functions}
    if [ -d "$path" ]; then
      FPATH="$path:$FPATH"
    fi
  fi
done
FPATH=$FPATH 

/private/tmp/nix-shell-48073-0/rc: line 5: --stdin: command not found

(note, actual escape characters replaced with ESC for readability)

chisui commented 1 year ago

Hm, the issue seems to be that $NIX_EXECUTING_SHELL is not set. See the line SHELL= and FPATH=$(echo 'echo $FPATH' | --stdin) right before the --stdin there should be the shell.

@mark-pictor-csec could you post the output of readlink /proc/$$/exe in zsh?

dsalaza4 commented 1 year ago

Hi @chisui

I am getting the same error as @mark-pictor-csec after installing bash 5.1 with nix-env -i bash-interactive and whitelisting it as the by-default bash shell by editing /etc/shells.

When I run readlink /proc/$$/exe on zsh I do not get anything:

$ echo $SHELL         
/bin/zsh
$ readlink /proc/$$/exe
$
mark-pictor-csec commented 1 year ago

sorry @chisui I should have checked for replies as with dsalaza4, I get nothing:

$ readlink /proc/$$/exe

$ readlink /proc/$$/exe | wc -c     
       0

$ zsh -c 'ls /proc/$$/exe'      
ls: /proc/40813/exe: No such file or directory