It's already there, doing exactly what you described today :-) :
https://github.com/Blaisorblade/cabal/blob/4ce674637f7ffca14b1e815309185940824a1f5d/cabal-install/Distribution/Client/Utils.hs#L149