New Package: A minimal configuration variable (CFV) file format

  • Package
  • Haskell
  • Web
  • Development

I just published a new package called CFV to Hackage. This is a parser for configuration files that contain variable declarations. Typically, developing web apps requires connecting to various services that require configuration settings that may change based on the stage of development. Furthermore, these settings might require access tokens and other fields that can change. Good software engineering says we shouldn’t just hardcode these.

I know, I know, you are thinking that I just described DotEnv files. Well, basically yes, but DotEnv files and their libraries that parse them also assume you want to load them into your environment variables, but I don’t always want that. In addition, there are not many features supported by DotEnv files that help us prevent common problems with using files of this style. Lastly, I want to have more than just one .env file.

So I decided to write my own file format for dealing with declaring configuration variables for my developments. Before discussing the features, here is a simple example of a project_awesome.cfv file:

-- Configuration Settings for Project Awesome

stage = "development";  -- Toggle for development stage
today = `date -I`;      -- Today's date in YYYY-MM-DD

-- Access token for our super secret backend
secret access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkphbmUgRG9lIiwiaWF0IjoxNzYyODY5NTAwLCJleHAiOjE3NjI4NzMxMDB9.Zm9yLWRlbW8tcHVycG9zZXMtb25seS1ub3QtYS1yZWFsLXNpZ25hdHVyZQ';

Comments can occur anywhere and use Haskell’s single-line comment syntax. Then there are two types of variable declarations:

  1. Public variable declarations are declared with no attribute.
  2. Secret variable declarations are declared with the secret attribute. This attribute is kept after parsing, so that these can be treated specially, because the user considers them to be sensitive.

Then a variable can be declared using the syntax:

The main parts of the API are:

That’s it! I plan to add various features to this as I go. Here are a few I have in mind:

PRs welcome!