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

setup-hook: bad substitution #14

Open
chuwy opened this issue Dec 19, 2019 · 6 comments
Open

setup-hook: bad substitution #14

chuwy opened this issue Dec 19, 2019 · 6 comments

Comments

@chuwy
Copy link

chuwy commented Dec 19, 2019

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 NixOS/nixpkgs#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
Copy link
Author

chuwy commented Dec 19, 2019

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

@chuwy chuwy closed this as completed Dec 20, 2019
@chisui
Copy link
Owner

chisui commented Dec 20, 2019

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
Copy link

On MacOS you have to have a bash with version 4 or greater. #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
Copy link
Owner

chisui commented May 4, 2023

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
Copy link

dsalaza4 commented May 10, 2023

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
Copy link

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

@chisui chisui reopened this Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants