Parameterized environment variables

Hello again. I have the following bit of code which loads in configuration from the environment.

{-
  Ideally this would be automatically generated from a dhall file from within
  `og-config`
-}
let Lib = ../../og-config/lib.dhall

let config = \(app : Lib.App.Config) ->
  (Lib.App.Builder.make app)::
    { MONGO =
      { host = env:APP1__MONGO__host as Text ? app.MONGO.host
      , port = env:APP1__MONGO__port as Text ? app.MONGO.port
      , username = env:APP1__MONGO__username as Text ? app.MONGO.username
      , password = env:APP1_MONGO__password as Text ? app.MONGO.password
      , database = env:APP1__MONGO__database as Text ? app.MONGO.database
      , poolSize = env:APP1__MONGO__poolSize as Text ? app.MONGO.poolSize
      , authenticationDatabase =
          env:APP1__MONGO__authenticationDatabase as Text
          ? app.MONGO.authenticationDatabase
      }
    }


in { config = config }

Is there a way which I could parameterize the env: call so that APP1 can be dynamically provided?

1 Like

@scull7: In general, you cannot have computed environment variable names as the language currently stands.

The main reason this is not currently possible is because the interpreter works in phases where the import resolution phase precedes the type-checking phase which in turn precedes the evaluation phase, so you wouldn’t be able to evaluate the variable name before the import is resolved.