Patches taken from https://github.com/spack/spack/pull/15403
mentioned in merge request !790 (closed)