16

I am trying to use environ to access environment variables specified in my project.clj :dev profile. This looks like a nice way to set up different configuration options, but I can't seem to get it to work. My project.clj entry looks like this:

:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                      [ring-mock "0.1.5"]]
       :env {:foo "FOO" :bar "BAR"}}}

If I run lein repl and require then enter (with in-ns) a namespace from my project, environ.core/env just returns nil:

(environ.core/env :foo)
nil

Adding an :env entry to the :user profile in .lein/profiles.clj also doesn't work. What am I doing wrong?

ChrisM
  • 2,128
  • 1
  • 23
  • 41
  • If you run `(System/getenv)` do you see "FOO", or maybe "foo" or ":foo" as any of the keys? I notice that (env.core/env :pwd) returns the value referenced by the "PWD" key in my environment for example. – noisesmith Feb 02 '14 at 23:26
  • @noisesmith Well I can pick up environment variables like PATH with environ, it's just the ones defined under my defproject :profiles that it doesn't seem to see. No, I don't see any variation on foo. – ChrisM Feb 02 '14 at 23:38
  • If environ can get other env vars, this is not an environ problem, it is a leiningen one. Most likely you aren't adding the env vars correctly. – noisesmith Feb 02 '14 at 23:42
  • @noisesmith That's just what I thought, but I'm pretty sure I am. Compare to the accepted answer [here](http://stackoverflow.com/questions/20469012/how-to-access-values-on-leiningen-profiles). – ChrisM Feb 02 '14 at 23:49

1 Answers1

20

OK, it was a case of reading the docs more thoroughly. :) To access environment variables specified in the project map you need the lein-environ plugin. Add it like this:

:plugins [[lein-environ "0.4.0"]]

That worked. It's easy to miss that in the docs though.

ChrisM
  • 2,128
  • 1
  • 23
  • 41