4
votes

I have an elixir application, an application server, that would benefit from start up parameters. This application uses an ecto repository, so I can store an app server's configuration there, but I'd still need a configuration key for what to retrieve from the db.

Presently I've been using config.exs for the server application (the whole application is an umbrella project), but obviously this only handles one static configuration.

My question is: Can I use mix to specify what config file I'd like to use? I know that there are several functions in the Mix library, but from what I've read they're all functions that can be used after the application has started. And, similarly, could I use mix to load configuration files for any of the child applications?

Thanks for any help provided.

EDIT: As requested... Once the main umbrella project has been started (not knowing everything there is to know about umbrella projects, I'll assume that child application start up order won't matter; details to work out later) the server child application, using its start up arguments, queries the child application repository (Config.Query, contain queries to be run against the query table) for the complete application server configuration: listen ipAddress and port, code directory, max number of connections, etc. This configuration is maintained by a genServer which can be queried by other processes as necessary.

defmodule Hermes.Server.Info do
    use GenServer

    def start_link() do
        GenServer.start_link(__MODULE__, :ok, [name: :hermes_server_configuration])
    end

    def init(:ok) do
        system        = Application.get_env(:hermes_server, :system, "dev")
        client        = Application.get_env(:hermes_server, :client, "testClient")
        appServerName = Application.get_env(:hermes_server, :appServername, "testAppServerOne")
        config        = Config.Query.get_config(system, client, appServerName)
        {:ok, config}
    end
end

So, if I could do something similar to elixir --detached -S mix run --config pathToConfigFile, even if that means creating my own bash script to get to the correct directory, that would be the best option in my opinion. But, having read Patrick's answer, that doesn't look possible; hadn't read that config files are something dealt with at compile time.

1
This is a very good question. Imagine you have projects A and B, you may already have noticed that configuration in project A does not affect project B. So what do you intend to do? Configure project A in some specific way when starting B? Can you provide some pseudo code snippets of how you would like this to work?José Valim

1 Answers

4
votes

The built in configuration is evaluated at compile time. To get runtime configuration you need to use a third party library such as conform or roll your own solution.