Fork me on GitHub
#leiningen
<
2016-08-24
>
lumengxi05:08:31

Hey, i have a question on accessing environment variables in project.clj and hope someone can help me out: I am writing a lein plugin, and i need to read something like {:config :env/CONFIG_A} in project.clj, but couldnt get it work. Looking at other projects (lein plugins) but I couldnt figure out how this works

danielcompton08:08:40

Can you explain a bit further? I use lein-environ for env stuff, but I think it’s a bit different to what you’re wanting to do

lumengxi21:08:00

@danielcompton basically, i have seen something like this {:user-name :env/USER_NAME} in project.clj, and it got picked up as environment variables

lumengxi21:08:12

but i just couldnt figure out how that worked

danielcompton21:08:30

That will be plugin specific I expect

danielcompton21:08:24

but you would iterate over the kv in your config, check each value to see if it is a keyword, and if so if it's namespace is env

danielcompton21:08:20

If so, then use (System/getEnv.. to look up the name of the keyword

danielcompton21:08:39

> "Keywords with a project namespace are looked up in the project map. For example:"

danielcompton21:08:38

but AFAICT this is specific to repositories, not a general functionality that you can use anywhere in project.clj

danielcompton21:08:47

The philosophy of Leiningen is to lean towards repeatable builds, so generally you only want environment variables for things that shouldn’t be stored in code, e.g. passwords