Move buildEnv to where it's relevant.