include-env-0.5.0.0: Include the value of an environment variable at compile time
Safe HaskellNone
LanguageHaskell2010

IncludeEnv.TH

Contents

Description

Include the value of an environment variable in the binary at compile time.

Rationale

Users might want to embed secrets (e.g. API keys, database connection strings) inside production artifacts without checking these into the repository.

Examples

NB : all library functions require the TemplateHaskell language extension.

Include a single variable

In this case, the name of the user's current shell) :

import IncludeEnv.TH (includeEnv)

$(includeEnv "SHELL" "shl")
shl :: String

main :: IO ()
main = putStrLn $ unwords ["your current shell :", shl]

Include a group of variables as a name-value map

import IncludeEnv.TH (includeEnvMap)

env = $(includeEnvMap ["TERM", "USER"])
>>> env
fromList [("TERM","dumb"),("USER","marco")]
Synopsis

Documentation

includeEnv Source #

Arguments

:: String

name of environment variable to be looked up

-> String

name of new value

-> Q [Dec] 

Include the value of an environment variable at compile time.

A fresh variable of type String is declared each time this is computation is evaluated.

Note : will crash with error if the environment variable is not found.

includeEnvLenient Source #

Arguments

:: String

name of environment variable to be looked up

-> String

name of new value

-> Q [Dec] 

Like includeEnv but only prints a warning if the environment variable cannot be found.

NB : If the lookup fails, the declared value will contain an _empty string_ .

includeEnvMaybe Source #

Arguments

:: String

name of environment variable to be looked up

-> Q Exp 

Like includeEnv but produces a 'Maybe String'

Use case : The program needs to be compiled against two different environments that may have different sets of environment variables. includeEnvMaybe lets you account for the results of multiple such lookups at runtime.

Since: 0.4.0.0

containers

includeEnvMap Source #

Arguments

:: Foldable t 
=> t String

names of environment variable to be looked up

-> Q Exp 

Lookup a number of environment variables and populate a Map with the result

NB: if a variable name cannot be found, the corresponding entry will be missing

Since: 0.5.0.0