How to set environment variables in dev.exs?

@Josh, here’s what I’m doing for now, which I’m happy with so far. :slight_smile:

Development

I find text files convenient in dev, and don’t want to have to export env vars every time I run the app locally.

config/dev.secret.exs contains dev secrets that shouldn’t be in version control. (secret_key_base keys could be moved into this file, but I’ve left mine in dev.exs for now as it’s only for signing and encrypting in dev while testing.)

.gitignore contains **/*.secret.exs so that ‘secret’ files are kept out of Git version control.

Production

I use Mix releases and use environment variables via systemd, and so keep the System.get_env(ENV_VAR) calls.

Important to note is that there’s a new recommended way of handling run time (as opposed to compile time) config in Elixir >= 1.9: the Config module. The whole page is worth reading, but here’s the upshot:

The Config module in Elixir was introduced in v1.9 as a replacement to Mix.Config , which was specific to Mix and has been deprecated.

You can leverage Config instead of Mix.Config in two steps. The first step is to replace use Mix.Config at the top of your config files by import Config .

In Phoenix, rename prod.secret.exs to the special filename releases.exs.

Then, the environment variables read in this file are read at run time on the server, and not when building (perhaps locally).