termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.98k stars 2.98k forks source link

Elixir mix can not install elixir packages #21204

Open callmiy opened 3 weeks ago

callmiy commented 3 weeks ago

I have elixir and erlang installed:

Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.17.2 (compiled with Erlang/OTP 25)

When I tried to install an elixir:

mix archive.install hex phx_new

I received the following error:

** (EXIT from #PID<0.95.0>) an exception was raised:
    ** (CaseClauseError) no case clause matching: :undefined
        (public_key 1.16.1) pubkey_os_cacerts.erl:40: :pubkey_os_cacerts.get/0
        (mix 1.17.2) lib/mix/utils.ex:664: Mix.Utils.read_httpc/1
        (mix 1.17.2) lib/mix/utils.ex:576: anonymous fn/2 in Mix.Utils.read_path/2
        (elixir 1.17.2) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
        (elixir 1.17.2) lib/task/supervised.ex:36: Task.Supervised.reply/4

15:29:42.543 [error] Task #PID<0.111.0> started from #PID<0.95.0> terminating
** (CaseClauseError) no case clause matching: :undefined
    (public_key 1.16.1) pubkey_os_cacerts.erl:40: :pubkey_os_cacerts.get/0
    (mix 1.17.2) lib/mix/utils.ex:664: Mix.Utils.read_httpc/1
    (mix 1.17.2) lib/mix/utils.ex:576: anonymous fn/2 in Mix.Utils.read_path/2
    (elixir 1.17.2) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.17.2) lib/task/supervised.ex:36: Task.Supervised.reply/4
Function: #Function<5.19587555/0 in Mix.Utils.read_path/2>
    Args: []
callmiy commented 3 weeks ago

May be it is related to this line TERMUX_PKG_SRCURL=https://github.com/elixir-lang/elixir/releases/download/v${TERMUX_PKG_VERSION}/elixir-otp-25.zip which is hardcoded to otp-25 while the installed erlang is otp-27

Biswa96 commented 3 weeks ago

...which is hardcoded to otp-25 while the installed erlang is otp-27

Thank you for reporting the issue. I have added a pull request with your suggestion. Would you like to test the packages from GitHub Actions artifacts of that pull request? Link https://github.com/termux/termux-packages/actions/runs/10496812629

callmiy commented 3 weeks ago

Thanks for the quick response. The PR fixed the erlang OTP version but does not fix the error I was getting with mix archive.install hex phx_new.

Biswa96 commented 3 weeks ago

Could you explain what does those error mean in simple English? The error output is more cryptic than C++ compiler error.

Biswa96 commented 3 weeks ago

The issue has not been fixed yet. Please feel free to create pull request to fix the issue.

dragon0 commented 1 week ago

The issue is that the Erlang runtime is not loading the root CA certificates. This might be fixable with a compile-time option for the Erlang package, but I'm not sure. As a workaround, I added the following function call in an Elixir script after ensuring the ca-certificates package was installed: :pubkey_os_cacerts.load(["/data/data/com.termux/files/usr/etc/tls/cert.pem"]). This exception was not raised when I ran that script. I expected to need to include this call in any code that needed to make HTTPS connections, but interestingly the :pubkey_os_cacerts.get/0 function no longer raised an exception in subsequent runs, at least for mix-related commands. Maybe I just got lucky. But this suggests that it might be possible to just paste that function call in an iex shell and not need to run it again, IDK.

dragon0 commented 1 week ago

@callmiy Your mix archive.install hex phx_new also worked for me after I ran the above :pubkey_os_cacerts.load(...):

$ mix archive.install hex phx_new
Resolving Hex dependencies...
Resolution completed in 0.029s
New:
  phx_new 1.7.14
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 11 files (.ex)
Generated phx_new app
Generated archive "phx_new-1.7.14.ez" with MIX_ENV=prod
Are you sure you want to install "phx_new-1.7.14.ez"? [Yn]
* creating /data/data/com.termux/files/home/.mix/archives/phx_new-1.7.14
callmiy commented 1 week ago

@dragon0 Thanks—your fix worked! I posted about the issue on the Erlang forum. Hopefully, someone can confirm your suspicion, and we can move forward.