HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleyaml-0.11.11.2Haskell2010

Data.Yaml.Config

Functionality for using YAML as configuration files

In particular, merging environment variables with yaml values

loadYamlSettings is a high-level API for loading YAML and merging environment variables. A yaml value of _env:ENV_VAR:default will lookup the environment variable ENV_VAR.

On a historical note, this code was taken directly from the yesod web framework's configuration module.

  • 1 type
  • 10 values
  • Packageyaml-0.11.11.2
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceConfig.hs

High-level

2 declarations
valueloadYamlSettings
  1. :: FromJSON settings
  2. => [FilePath]

    run time config files to use, earlier files have precedence

  3. -> [Value]

    any other values to use, usually from compile time config. overridden by files

  4. -> EnvUsage
  5. -> IO settings
#

Load the settings from the following three sources:

  • Run time config files

  • Run time environment variables

  • The default compile time config file

For example, to load up settings from config/foo.yaml and allow overriding from the actual environment, you can use:

loadYamlSettings ["config/foo.yaml"] [] useEnv
valueloadYamlSettingsArgs
  1. :: FromJSON settings
  2. => [Value]

    any other values to use, usually from compile time config. overridden by files

  3. -> EnvUsage

    use environment variables

  4. -> IO settings
#

Same as loadYamlSettings, but get the list of runtime config files from the command line arguments.

EnvUsage

datadata EnvUsage
#

Defines how we want to use the environment variables when loading a config file. Use the smart constructors provided by this module.

valueignoreEnv :: EnvUsage
#

Do not use any environment variables, instead relying on defaults values in the config file.

valueuseEnv :: EnvUsage
#

Use environment variables when available, otherwise use defaults.

valuerequireEnv :: EnvUsage
#

Do not use default values from the config file, but instead take all overrides from the environment. If a value is missing, loading the file will throw an exception.

Lower level

3 declarations
valueapplyEnvValue
  1. :: Bool

    require an environment variable to be present?

  2. -> KeyMap Text
  3. -> Value
  4. -> Value
#

Override environment variable placeholders in the given Value with values from the environment.

If the first argument is True, then all placeholders _must_ be provided by the actual environment. Otherwise, default values from the Value will be used.