This PR (perhaps foolishly) aims to import the changes in https://github.com/spack/spack/pull/43062...