Fixes NixOS/nixpkgs#25139 by backporting patch applied in ghc trunk: https://phabricator.haskell.org/D2823