Allow the use of closures for environment detection. (Same as https://github.com/themosis/themosis/pull/29)

This is the same as https://github.com/themosis/themosis/pull/29 but this is in a different branch.