Skip to content

No longer generate config for mix new #8932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2019
Merged

No longer generate config for mix new #8932

merged 2 commits into from
Apr 4, 2019

Conversation

josevalim
Copy link
Member

The fact we explicitly told developers to configure their
application in the config file and access it with
Application.get_env/2, probably led many to rely on
the application environment when better options are
available.

Furthermore, mix new is mostly used for libraries,
where config is even less important, as configuration
from libraries is not transitive.

Developers that need the config, can simply add it back
by calling:

echo "use Mix.Config" > config/config.exs

This commit removes config for new apps and deprecate
the --config flag, which cannot perform deep merges.
Note we do keep the config for umbrellas, as umbrellas
are about applications and not libraries (plus we need
the umbrella children to share and point to an existing
config).

Closes #8815.
Closes #8811.

The fact we explicitly told developers to configure their
application in the config file and access it with
`Application.get_env/2`, probably led many to rely on
the application environment when better options are
available.

Furthermore, `mix new` is mostly used for libraries,
where config is even less important, as configuration
from libraries is not transitive.

Developers that need the config, can simply add it back
by calling:

    echo "use Mix.Config" > config/config.exs

This commit removes config for new apps and deprecate
the `--config` flag, which cannot perform deep merges.
Note we do keep the config for umbrellas, as umbrellas
are about applications and not libraries (plus we need
the umbrella children to share and point to an existing
config).

Closes #8815.
Closes #8811.
@josevalim josevalim merged commit e436fa7 into master Apr 4, 2019
@josevalim josevalim deleted the jv-less-config branch April 4, 2019 12:11
@perrycate
Copy link

perrycate commented Aug 30, 2019

Pardon my ignorance, but what are the aforementioned "better options"? Based on this guide it seems the alternative to using a config.exs file is to add config parameters to env in application/0 in mix.exs.

There clearly are differences between the two, as I am unable to set module attributes using Application.fetch_env!/2 using the latter config option and using iex -S mix. I'm having trouble groking what those differences are, though, and what the best practices for configuration in general are.

(If it makes a difference, I have been learning elixir by working through the book "Programming Elixir >= 1.6 by Dave Thomas. It seems it was written before this decision was made, as the example I'm working through assumes config/config.exs exists and is the best place to put application configuration. Is there another resource that would be better for a new user such as myself to consult?)

@vans163
Copy link
Contributor

vans163 commented Aug 30, 2019

Pardon my ignorance, but what are the aforementioned "better options"? Based on this guide it seems the alternative to using a config.exs file is to add config parameters to env in application/0 in mix.exs.

There clearly are differences between the two, as I am unable to set module attributes using Application.fetch_env!/2 using the latter config option and using iex -S mix. I'm having trouble groking what those differences are, though, and what the best practices for configuration in general are.

(If it makes a difference, I have been learning elixir by working through the book "Programming Elixir >= 1.6 by Dave Thomas. It seems it was written before this decision was made, as the example I'm working through assumes config/config.exs exists and is the best place to put application configuration. Is there another resource that would be better for a new user such as myself to consult?)

An option is to:
Create a .env file and source it or pass env vars directly on commandline. Then use :persistent_term.put/2, :persistent_term.get/1 to set it emulator wide in your initial module once you read it back from env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Do not generate config/config.exs for mix new Config from mix run --config invocations doesn't get deeply merged
5 participants