emadalam
Hey all ![]()
I just published mahaul package for streamlining the environment variables usage in your Elixir apps. Parse and validate your environment variables easily in Elixir with the following benefits.
- Compile time access guarantees
- Parsed values with accurate elixir data types
- Validation of required values before app boot
mixenvironment specific defaults and fallbacks
Read more for understanding why to use this package and its benefits. The complete documentation for mahaul is available online at HexDocs.
We have been using this in production and it has already saved us from bad releases where we deployed to production and forgot to set the needed environment variables after an update. Though it seems to work nicely for a variety of use cases, I’m relatively new to Elixir (only a few months) so I’d love your inputs and reviews on this.
Thanks to this wonderful Elixir community, I’ve never come across anything like this from a community standpoint, so hats off, I’m enjoying every moment of it since the day I started learning Elixir ![]()
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 15 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
stevensonmt
LIGHTBULB
I get it now. Thanks!
emadalam
Can you give some brief example of how such a dynamic pattern matching can work at compile time? Form what I can think of, the following will give you runtime errors without any compile time warnings.
vs
stevensonmt
Thanks for clarifying as I had indeed misunderstood.
I’m still not sure I follow here though. This seems like with pattern matching you could hard code the strings for the env variables of interest and have the same sort of confidence. I can see that
mahaulprovides a single interface with the system env where you handle checking for the variables and providing defaults or handling errors rather than needing to do so everywhere you use the env variable in the application.Mahaulalso seems to make it a lot easier to use different variables for different environments and to update them easily when the names of variables change between versions or something.This sounds like a true win for me.
D4no0
Well, the point of configuration is to use them in your code later, just as libraries use them and you can do that easily by calling
get_env/3orfetch_env/2, however taking in consideration the limitation of the configuration/compilation it seems that the only way to enforce something at compile-time is to make a custom module.It would be great if such a functionality were to be introduced somewhere in the elixir internals so it could be used in all configurations.
emadalam
I certainly use environment variables in my code beyond just config files. So even though the idea of macros in
runtime.exsis certainly nice, I still want to be able to access those environment variables values independently in my code as needed. This is why a separately initialized module where I can see/configure all the environment variables used by my app in one glance, makes more sense to me from flexibility and ease of use standpoint.D4no0
Ah true, quite sad but it makes sense. Well at least for
runtime.exsit would be nice to have the check.LostKobrakai
You can only do that with
Config.Providerimplementations (e.g. runtime.exs), but that won’t be able to provide compile time configuration. The chicken/egg situation means config first then applications, because you need to be able to configure said applications. So applications cannot be available or be used inconfig/config.exs.D4no0
The usage of environment variables is not in question here, the thing that I try to point out is that I would like to use this library, however I would like the environment variable specification defined in the
config.exsdirectly, not with a separate module.In my opinion there is no reason to create your own wrappers over the config way of storing those values, however a check of the environment value type is a great thing.
To make my point cleaner, I will illustrate an
dev.exsexample:emadalam
@D4no0 IMHO I don’t think elixir configs are limiting in any way, if anything I’ve found it to be very well thought and structured with perfect balance of standardization vs flexibility. I’ve rarely come across anything so flexible and feature complete that’s baked in as part of the core language feature, as elixir configs.
I feel it’s important to understand there’s a difference between app configuration and environment variables and they are not a replacement to each other rather environment variables compliment your app’s configurability. You can choose to configure your app with static values or environment variables, the choice is totally up to you. The fact that elixir configs lets you achieve this in a feature complete way, in itself is wonderful to me.
D4no0
Oh I see, this is a limitation of elixir configs. It would be nice to also have a macro or sigil to define a typed/checked environment variable directly into config, without generating the function at compile-time of course, as I hate having to look into 10 different files to find the actual config.