Evaluating an Elixir script at runtime for configuration

Is it possible to evaluate an arbitrary Elixir script at runtime that calls Config.config/2 (e.g. from releases.exs?)

This is slightly different from releases.exs, I think, because I cannot provide or modify releases.exs at runtime.

(The reason is that my application configuration uses atoms and keyword lists, and it would be cumbersome to have to load from something like JSON where I would have to convert the right strings into atoms, etc. Better solutions appreciated.)


Have you tried using import_config yet? Anyway, for less-trivial cases you can reach for an implementation of Config.Provider, which would be a good approach for things like loading config details from files or network requests. The canonical example actually is loading a JSON file.

1 Like

import_config isn’t allowed in releases.ex (some effort was spent on disabling it in that file …)

I might just go with calling Code.eval_file/1 in releases.exs, or simply modifying/overwriting releases.exs in the deployment.