env: factor out environ map construction
Created by: keegancsmith
See second commit. First commit is undoing the revert of #11015.
There was a bug in the implementation. We iterated over the empty map instead of os.Environ(). By factoring it out we can test it.