Regression with flox 1.0.5

Hi, there seems to be a regression with flox 1.0.5.

I am now seeing this message again:

/Users/etorreborre/.cache/flox/run/etorreborre/default.d62f59a1/activate/bash:13: command not found: shopt
/nix/store/ command not found: shopt

This is when I enter a directory with direnv and my configuration is

eval "$(flox activate -d $FLOX/my_env)"

Then I get a direnv message:

direnv: ([/Users/etorreborre/.cache/flox/run/etorreborre/default.d62f59a1/bin/direnv export zsh]) is taking a while to execute. Use CTRL-C to give up.

We’re looking into it! we made a number of activate changes in this release. will get back to you shortly

With 1.05 we changed the order of hook.on-activate and profile scripts such that the hooks are always run first now (and always in Bash). This allows you to eval in your hook and it should just work in most cases.

Could you share your manifest so I could take a look and do some debugging?

Thanks for helping. I sent the result of flox -vv activate and my manifest file to Michael via the Slack workspace.

1 Like

Thanks again Eric for sending those traces offline. We’ll get back to you ASAP with a workaround. :+1:

Thanks again Eric for your patience. As a workaround, please try:

eval "$(FLOX_SHELL=bash flox activate -d $FLOX/my_env)"

The reason for the problem is because direnv always parses the contents of .envrc in a (non-interactive) bash sub-shell, irrespective of the shell that you are using. (This is similar to the way that the flox on-activate hook is always processed using bash, for much the same reasons.) The FLOX_SHELL environment variable provides a way to override the flox shell detection logic in the meantime, but I’ll also update the code to always switch into bash mode when we detect direnv as the parent process of the flox invocation.

Thanks again for the bug report!

Hi Eric, I think I know what’s going on.

Your use of direnv is taking place within an existing flox activation, and it is that outermost flox activate invocation that is a) correctly detecting your shell as /bin/zsh and b) leaking the FLOX_SHELL=/bin/zsh environment variable into your subsequent environment. As a result, when you use direnv it invokes flox with FLOX_SHELL defined and pointing to zsh, which then causes flox to emit zsh syntax when direnv invokes flox from the .envrc (using bash).

The fix for this should be to stop leaking FLOX_SHELL into the environment - I’ll draw up a PR for that ASAP.

Here’s a reproducer that illustrates the behavior:

flox [limeytexan/default (remote)] brantley@Michaels-MacBook-Pro ~ % echo $FLOX_SHELL

flox [limeytexan/default (remote)] brantley@Michaels-MacBook-Pro ~ % cd direnvtest
direnv: loading ~/direnvtest/.envrc
flox [limeytexan/default (remote)] brantley@Michaels-MacBook-Pro direnvtest % cd ..
direnv: unloading
flox [limeytexan/default (remote)] brantley@Michaels-MacBook-Pro ~ % export FLOX_SHELL=$SHELL
flox [limeytexan/default (remote)] brantley@Michaels-MacBook-Pro ~ % echo $FLOX_SHELL        
flox [limeytexan/default (remote)] brantley@Michaels-MacBook-Pro ~ % cd direnvtest
direnv: loading ~/direnvtest/.envrc
/private/tmp/direnvtest/.flox/run/aarch64-darwin.direnvtest/activate.d/zsh:36: unexpected token `(', conditional binary operator expected
flox [limeytexan/default (remote)] brantley@Michaels-MacBook-Pro direnvtest % 

Will let you know once we release a patch for this.

1 Like