Generate configuration before data directory

This is #224 rebased on top of the latest master.