mblagusz

mblagusz

Runtime configuration for a dependent library

We are in the process of moving some shared functionality (mail sending) into a separate application that’s a dependency of our main app. That is, a shared library.

The problem we’re running into is that the mail configuration currently lives inside config/runtime.exs in our main application. If we move it to config/runtime.exs inside the dependent library, then Application.get_env(:mailer, …) doesn’t find it anymore. It would seem that only the “main” runtime.exs file is being loaded by mix run.

I see some libraries use files like config/prod.exs, but I want the shared configuration to read environment variables at startup. Is there a pattern that will let me do this?

Most Liked

LostKobrakai

LostKobrakai

Not just runtime.exs. All config can only come from the top level mix project you’re on. Config of dependencies is ignored.

mayel

mayel

Not only that, but it is generally discouraged to use the config for libraries (see the infobox at Config — Elixir v1.16.2).

I personally consider one’s “internal” dependencies to be an exception, and so this is my approach to runtime config for such libraries:

in the main app’s runtime.exs:

[SubApp1.RuntimeConfig]
|> Enum.each(&apply(&1, :config))

in the dependency (at lib/runtime_config.exs):

defmodule SubApp1.RuntimeConfig do
  def config do
    import Config
    
    config :sub_app1,
    	key: System.get_env("SUB_APP1_key", "default_val")

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement