Fork me on GitHub

Is there a good way to store and load (non-committed) local environment variables? I tried using: but I couldn't get it to work with re-natal... I just have a filepath I need to manually set for development, but its different on each of my computers.


@kara if you are using Lein you could consider using :closure-defines with ~(System/getenv "MY_ENV_VAR"). You'd at least have to commit changes to your project.clj and the usage sites, but the actual value of MY_ENV_VAR can vary from box to box.


cool! That sounds like a good lead. Yeah, I'm Ok with commit the setup but the value I just didn't want in the repo since it's local system stuff. 😛


hi @U04VDQDDY... I was wondering if I could ask a follow up question on this... In the documentation for :closure-defines it says: > Vars must be specified as a namespace-qualified symbol, and their values must be a string, number, or a boolean but are you saying I can also use a function that resolves to one of those values? For example... I found this library: which is pretty much exactly what I'd like... but I need to "inject" the .env variables into clojurescript... could I do something like :closure-defines {"MY_ENV_VAR" ~(env "MY_ENV_VAR")} per your example? I'm using lein figwheel


Yes, the use of ~(env ...) is great, but the key should be namespace qualified, pointing to the var established by goog-define in your code


Do (doc goog-define) to see what I mean


ah, yes! I see that now. Ok, thanks. hopefully this works 🤞:skin-tone-2: 🙂


@kara We just use environ and load them with macros during compile-time.


enviorn? 🙂


So there's a gitignored config.edn with all the secrets and it's loaded via macros.


That works too... just be aware that if you put code like that into a JAR that you re-use, then it won't be cache-friendly (ClojureScript's 1.10.x shared AOT cache feature)


I don't think that's an issue for me... I'm trying to go after the '12 Factor App pattern' as stated in the readme so that seems to align with my specific use case


Also, I realized I was multitasking and provided two bad answers. We have two solutions, depending on the usage. For long-term secrets, we use a gitignored config.edn which is slurped at run-time, but that's only on the back-end. On the front-end, we use environ and bring in the secrets at macro expansion.


> bring in the secrets at macro expansion Let's pretend I have no idea what I'm doing here. 🙃 Is this basically saying... when the function is called it reads the value from the source?


really my use case is pretty simple. While I'm doing local development I want to change a path from the default (some crazy path nested in simulator) to somewhere else on my machine I can find the file. So in my case... ./data/develoment.realm but it needs a full path. I can just manually put in the path, but as I switch systems it's a headache and I don't really want it in the final codebase


I feel like... environ will work for this