How to use an app as a dependency and reuse its config?

I have an application, lets call it A, that is in its own repo and has some configuration, and can run on its own. I want to create another application B that extends the functionality of A (A already provides some extension points). My idea is to use A as a dependency of B. The configuration of B must be inherited from A, so B can start it without having to redefine the config. Is it a good idea to just import A’s config into B’s config?

I’d just copy the config file content because:

  • Eventually, the config will diverge.
  • If their is a large part of config that is static, maybe it is better to refactor it into code.
1 Like

That’s not how configuration in mix works. There’s just a single set of configuration and it’s provided by the mix project and that’s independent from any application or dependency within that mix project.

The only option dependencies have is ship defaults for their own app env, which you can set in the mix.exs (example).

So what’s the issue with this? Seems to work just fine

b/config/config.exs

import Config

import_config "../../a/config/config.exs"

b/mix.exs

  defp deps do
    [
      {:a, path: "../a"}
    ]
  end

If somewhere in A I am using for example Application.fetch_env!(:a, :x), then it works just fine when A is started both directly and as dependency of B. And B expectedly fails when I remove that import from its config