Mix does not recognize hex in MIX_HOME

,

Since we have to roll out our elixir build environment on our CI servers without additional downloads from external sources, we have always made use of the MIX_HOME variable to point to several essentials - rebar, rebar3, and a local version of hex - on a shared directory.

With elixir 1.6 we had this point to a directory containing this:

ls /tools/elixir/mix_home/*
/tools/elixir/mix_home/rebar  /5g/tools/elixir/mix_home/rebar3

/tools/elixir/mix_home/archives:
hex-0.17.6  hex-0.17.7

When trying to migrate to 1.10.4, we now have this:

ls /tools/elixir/mix_home/*
/tools/elixir/mix_home/rebar  /5g/tools/elixir/mix_home/rebar3

/tools/elixir/mix_home/archives:
hex-0.17.6  hex-0.17.7 hex-0.20.5

I checked the permissions and structure, it is the same for all three folders.

As each time before, I used the contents of my own ~/.mix/archives folder and copied to the share.

If I use the version from my own home directory, it recognizes Hex 0.20.5 to be present.
If I point MIX_HOME to /tools/elixir/mix_home just like I did before, it complains:

Mix requires Hex >= 0.19.0 but you have 0.17.6

The only difference I can see is that in my home, only hex-0.20.5 is installed, whereas here three different versions of hex are next to each other.

So can the code in https://github.com/elixir-lang/elixir/blob/1f739840924470c4d2b0eb18daa6a6cb5da991cd/lib/mix/lib/mix/hex.ex only ever pick the first version of a package it finds? I think I run into the ensure_updated?/0 function…

I copied the /tools/elixir/mix_home into a folder I have write access to, and there it works without warning.

Yet when I use a path on the read-only share, it doesn’t work…

Local -rw-r--r-- 1 me mygroup 3.2K Nov 13 18:33 hex.app
Remote -rw-r--r-- 1 tools groupimalsoin 3.2K Oct 13 15:00 hex.app

So can the code in https://github.com/elixir-lang/elixir/blob/1f739840924470c4d2b0eb18daa6a6cb5da991cd/lib/mix/lib/mix/hex.ex only ever pick the first version of a package it finds?

Yes, that’s basically how it works. The code loader does not perform version resolution. When you install hex on your local machine any old versions are uninstalled.

Remove the old versions and only keep the hex-0.20.5/ directory and it should work correctly.

Thank you.

I’ll have to see if I can use a newer Hex with elixir 1.6 for the transition period, though.

I’ll have to see if I can use a newer Hex with elixir 1.6 for the transition period, though.

You can use any version of Elixir back to 1.0.0 with the latest Hex version.

Note though that when Hex is installed with mix local.hex we pick a version of Hex that is compiled against the same version of Elixir that you currently use. If you use that same Hex installation with another Elixir version it is likely it wont work. So you will need multiple shared directories with different Hex installations if you need to support multiple Elixir versions.

1 Like

Yes, I see now how I can solve my problem. Thank you, again!

1 Like