title: Elixir/Phoenix: How to use third-party modules in config files?
body: <p>It seems that the way configuration files in phoenix are loaded and compiled pose a problem when using third-party modules in <code>config.exs</code> or <code>dev.exs/prod.exs/test.exs</code>.</p>
  
  <p>Example: To set up <a href="https://github.com/ueberauth/guardian" rel="noreferrer">Guardian</a> for JWT authentication I am trying to use the <a href="https://hexdocs.pm/jose/JOSE.JWK.html" rel="noreferrer"><code>JOSE.JWK</code></a> module for JWK creation / loading in my <code>config.exs</code>. I can use the module alright in the console with <code>iex -S mix phoenix.server</code>. It is of course installed as a dependency. The error I'm getting is </p>
  
  <pre><code>** (Mix.Config.LoadError) could not load config config/config.exs
      ** (UndefinedFunctionError) undefined function JOSE.JWK.from_file/2 (module JOSE.JWK is not available)
  </code></pre>
  
  <p>This is the code in my config.exs</p>
  
  <pre><code># Configure Guardian for JWT Authentication
  config :guardian, Guardian,
    allowed_algos: ["HS512"], # optional
    verify_module: Guardian.JWT,  # optional
    issuer: "MyApp",
    ttl: { 30, :days },
    verify_issuer: true, # optional
    secret_key: System.get_env("GUARDIAN_KEY_PASSPHRASE") |&gt; JOSE.JWK.from_file(System.get_env("GUARDIAN_KEY_FILE")),
    serializer: MyApp.GuardianSerializer
  </code></pre>
  
  <p>It works when I wrap the call to <code>JOSE.JWK.from_file/2</code> in an anonymous function. But of course the value of Guardian.config(:secret_key) is then the anonymous function itself and not its return value:</p>
  
  <pre><code># Configure Guardian for JWT Authentication
  config :guardian, Guardian,
    allowed_algos: ["HS512"], # optional
    verify_module: Guardian.JWT,  # optional
    issuer: "MyApp",
    ttl: { 30, :days },
    verify_issuer: true, # optional
    secret_key: fn -&gt; System.get_env("GUARDIAN_KEY_PASSPHRASE") |&gt; JOSE.JWK.from_file(System.get_env("GUARDIAN_KEY_FILE")) end,
    serializer: MyApp.GuardianSerializer
  </code></pre>
  
  <p>This is ok in this example since Guardian accepts a function for this config value. But I can imagine other situations where this could be a problem.</p>
  
  <p>Is this limitation on purpose? Am I missing something? Is there a way around this?</p>