Backporting https://github.com/haskell/cabal/pull/5351 which closed https://github.com/haskell/cabal/issues/2189