Search code examples
elixirphoenix-frameworkerlang-otpelixir-mix

Configuration file for MIX app as OTP app


I have an OTP Application (ChicagBoss actually). I'm trying to incorporate Phoenix app into it (as just casual OTP app).

I think that most of applications start, but I got error caused by lack of config file. How to provide configuration file to MIX application from outside? Especially in case when I try run it from rebar.How to provide the directory?


Solution

  • When using Erlang project you shouldn't use mix configs, but erlang configs instead. In your particular example the boss.config file. In boss.config you have a list of tuples:

    [{app, Options}, {second_app, Options}].
    

    In Erlang shell you can check the config for given application with:

    application:get_all_env(app).
    

    In mix config files you have something like:

    config :my_app, MyApp.Repo,
      adapter: Ecto.Adapters.Postgres
    

    and you can check the config with:

    Application.get_all_env(:my_app)
    

    All you need to do is translate configs from Elixir to Erlang and put them inside boss.config. For example the Ecto adapter from above would become:

    [...other apps...,
     {my_app, [{'Elixir.MyApp.Repo',
               [
                {adapter, 'Elixir.Ecto.Adapters.Postgres'}
               ]}]},
     ...other apps...
    ].
    

    Just remember that foo: "bar" is a keyword list [{foo, <<"bar">>}] and module names in Elixir Foo are atoms in Erlang 'Elixir.Foo'.

    Second option is to use Elixir umbrella project which pulls both Chicago Boss and Phoenix. In this case you would need to translate boss configs to Elixir.