Losing my aliases on `flox develop`

When I start flox develop in a given project I am currently losing the aliases which were instantiated with my .zshrc setup. In particular I have quite a lot of git shortcuts which I use all the time. Is there a hook on flox develop which could allow me to add those aliases back?


Hi Eric,

Apologies this area is a bit of a moving target at the moment. This should provide a workaround for you in the short term (you will need to pull version 0.0.9-r146 (flox/default) or 0.1.0-r287-0.0.9-r146 (flox/prerelease) hot off the assembly line):

flox pull -e flox/default # or flox/prerelease
flox activate -e flox/default # or flox/prerelease
. <(flox print-dev-env)

Explanation: flox develop is the flox-enhanced version of nix develop, which execs bash to launch the build shell complete with all the Nix builder functions. Zsh aliases will not survive in the (bash) build shell, and there’s really nothing we can do about that.

Conversely, flox print-dev-env is the flox-enhanced version of nix print-dev-env, which simply prints out the (posix sh) commands to be sourced for both the flox and Nix build environments. These can therefore be sourced from within your running zsh and your aliases will survive.

Finally, we’re working to make it possible to flox activate a project flox environment, which would only provide access to the project’s local flox environment but wouldn’t provide anything from the nix build environment. I’m not sure where exactly this would be useful, except for debugging situations like you find yourself in right now. :slight_smile:

Let us know if that works for you - thanks for flagging! :+1:


I tried this but I got an error

± flox --version                                                                                                                                                                                                                                                                                                                                                                                               Version: 0.1.0-r287-0.0.9-r146

± . <(flox print-dev-env)                                                                                                                                                                                                                                                                                                                                                                                      
/dev/fd/11:27: read-only variable: LINENO

Do you have any idea what could cause this? Possibly something in my zsh setup but I don’t know what.

Thanks again for the prompt feedback - very relevant. Let us think on this and get back to you, but in the meantime this should provide a workaround for you:

. <(flox print-dev-env | awk '{print} /unset _flox _floxPrompt1 _floxPrompt2/ {exit}')

I am still getting the same issue. Is there anything I can do to help you debug it?

Ah … you must have $FLOX_PROMPT_DISABLE set in your environment. Try this instead?

. <(flox print-dev-env | awk '{print} /unset shellHook/ {exit}')

What’s happening is that flox print-dev-env prints out the commands for the flox environment tuned for your shell (zsh), then invokes nix print-dev-env to print out the commands for the (bash) developer shell, and the latter is clearly not working with zsh. The awk invocation should have cut off the output after flox environment part, but the line I was expecting to see wasn’t there because you must not be using the flox prompt customizations. This new version (above) instead looks for the first line in the nix print-dev-env output rather than the last line in the flox print-dev-env output.

In general, a good way to debug is to save the output of flox print-dev-env to a file and then edit/source it directly. That way you can pinpoint exactly which line(s) are causing problems.

Thanks again for your patience with all this!

@etorreborre you may have seen our announcement earlier today of the latest release. This version should address your problem, albeit with a change in the command that you will invoke.

flox develop

As before, flox develop remains an enhanced version of nix develop wrapped in a project-based flox environment. It works like this:

  1. activates a project-based flox environment
  2. invokes exec nix develop to launch a shell equipped to build a Nix package

This shell launched in step 2 is referred to as the build shell (i.e. a shell that you can use to debug/develop the Nix expression for the build of a particular package), and while it can be useful for developing the software itself it is probably NOT what you want because it forces the use of bash (destroying your zsh aliases in the process).

flox print-dev-env

flox print-dev-env similarly wraps an invocation of nix print-dev-env with commands to activate a project-based flox environment, but again this output is only suitable for use with bash.

flox (activate|edit|list|install|remove|upgrade) :new:

This latest version updates a subset of flox “environment” commands to work with project-based environments. Simply type any of these commands from within a “floxified” project and it will operate on the local environment in preference to the (named) “default” environment.

Wrapping up …

The flox activate command should now provide exactly what you are looking for. :crossed_fingers: Simply invoke flox activate from within your project and it should automatically detect and activate the environment using your shell, not bash. To try it out:

  1. flox pull -e flox/prerelease
  2. flox activate -e flox/prerelease

… then from within your project clone:

  1. flox edit
  2. flox activate
  3. observe that you can invoke flox (edit|install|remove) from within the activated environment to install or remove packages without having to exit and re-enter the shell

Please give it a try and let us know how it goes - many thanks as ever for being patient and providing us with such excellent feedback!

Hi Michael,

I tried what you suggested, and maybe I did not understand something.

On a rust project I am running flox activate and it seems that I am getting an empty environment scoped to that project. I was actually expecting to have on my path the cargo version that is compatible with my project configuration. It is important not only because I’d rather stay in sync with the project definition but also because the project defines some paths to libs that VSCode needs to have in order to start properly. Is it possible to have both worlds :slight_smile: (project scoped environment + dev dependencies)?

Can you try this for me?

  • flox develop to enter a nix develop shell
  • flox activate

That should allow you to launch a zsh from within the bash build shell, inheriting the effects of the nix develop invocation.

Let me know if that provides what you are looking for - if so we can wrap this up more nicely for you in a single invocation.

1 Like

Yes, that works fine!

1 Like