The application/0 definition in a typical mix.exs file has an essential shape like this:
def application() do
[mod: {MyApp, []}]
end
… where a tuple is given to the key :mod containing the application callback module and the start argument.
No idea why, but the thought occurred to me, why are an Application’s children usually defined in the Application module itself? In this example, for instance:
defmodule MyApp do
use Application
def start(_type, _init_arg) do
children = [{Cluster.Supervisor, [topologies, [name: MyApp.Cluster]]}]]}]
Supervisor.start_link(children, strategy: :one_for_one)
end
end
… rather than passed to start/2 by the mix.exs file? So, I’ve spent the last several years thinking this was just a convention, except that it seems like libcluster won’t automatically connect nodes if I rely on mix.exs in this way. In a bare application, this structure:
def application do
topologies = Application.get_env(:libcluster, :topologies) || []
[
mod: {
MyOtherApp,
[children: [{Cluster.Supervisor, [topologies, [name: MyApp.Cluster]]}]]
}
]
end
… and …
defmodule MyApp do
use Application
def start(_type, init_arg) do
Supervisor.start_link(init_arg[:children], strategy: :one_for_one)
end
end
… which I would’ve assumed was equivalent, doesn’t work. So there’s definitely a difference here that I’m not catching, but I have no idea what it might be.




















