Nixpkgs: "bad substitution" error on darwin

Created on 22 Oct 2019  路  6Comments  路  Source: NixOS/nixpkgs

Describe the bug
Since this commit:
https://github.com/NixOS/nixpkgs/commit/bbc5b22ad82f89d2605ab91073012b12cabe87c3
Whenever I run commands like:
nix-shell -p hello
I get the following error:

/nix/store/v94xrmhkljhb44v2shcpv74gxg1ii1f1-cctools-binutils-darwin-wrapper/nix-support/setup-hook: line 140: ${role_pre}${cmd^^}=${cmd}: bad substitution

Additional context
My default shell is zsh, which has been the cause of some issues at times.

Metadata

 - 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(root): `""`
 - channels(val): `"nixpkgs-20.03pre197510.4b0508a5853"`
 - nixpkgs: `/Users/val/.nix-defexpr/channels/nixpkgs`

Paging @xzfc in particular. Let me know how I can help!

bug stale darwin

Most helpful comment

Thanks. I personally solved it by:

brew update
brew install bash

Which installed an ambient bash v5.0.

Feel free to close this if you think you're done tracking this concern.

All 6 comments

You need recent bash (>=4) as macOS has outdated bash by default.

I'm not sure how nix behaves on macOS, but try either of the following:

  1. If you have $NIX_BUILD_SHELL environment variable, unset it.
    unset NIX_BUILD_SHELL; nix-shell -p hello
  2. export NIX_BUILD_SHELL=$(nix-build -A bashInteractive '<nixpkgs>')/bin/bash; nix-shell -p hello
  3. Update your system bash or install it via nix: nix-env -iA nixpkgs.bashInteractive

Thanks. I personally solved it by:

brew update
brew install bash

Which installed an ambient bash v5.0.

Feel free to close this if you think you're done tracking this concern.

Nix should use bashInteractive from Nixpkgs. I suspect it's hitting some error and falling back here:

https://github.com/NixOS/nix/blob/7c74f075f4a7274ad38c90085cc269a19a977438/src/nix-build/nix-build.cc#L357

Thanks. I personally solved it by:

brew update
brew install bash

I could also solve the issue for me with these steps.

@matthewbauer I got this issue on macOS, and installing via @xzfc's comment worked out well (which was also the solution you mentioned). I am running macOS Catalina, and wanted a pure nix/macOS machine, so for me this was a better solution.

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

grahamc picture grahamc  路  77Comments

peti picture peti  路  75Comments

Infinisil picture Infinisil  路  146Comments

ttuegel picture ttuegel  路  98Comments

grahamc picture grahamc  路  88Comments