How to add a config file to a livebook?

Hello everyone,

I’m trying to add a secret to my livebook. ( I need to have some credentials but I don’t want to save them in the livebook directy)

I tried the following in the ‘Notebook dependencies and setup’

Mix.install([
  {:req, "~> 0.2.1"},
  {:jason, "~> 1.3"},
  {:kino, "~> 0.5.0"}
],
config_path: "<full_path>/config/config.exs"
)

but if I now try to access the config via Application.get_all_env(:apaleo_api) the return is empty.

config.exs:

import Config

config :apaleo_api, :basic_auth,
  username: "username",
  password: "password"

Maybe someone can tell me what I am doing wrong …

1 Like

I think I found a solution with:

Mix.install([
  {:req, "~> 0.2.1"},
  {:jason, "~> 1.3"},
  {:kino, "~> 0.5.0"}
],
config: Config.Reader.read!("#{__DIR__}/config/config.exs")
)
2 Likes

That’s the preferred approach according to the docs: Mix — Mix v1.14.0. There’s also a :config_path option as of the newest Elixir 1.14 that loads the file for you as well as a paired runtime.exs if it’s in the same directory.

1 Like