getInstalledPackages :: Verbosity -> PackageDBStack -> ProgramConfiguration
                     -> IO (PackageIndex InstalledPackageInfo)
getInstalledPackages verbosity packagedbs conf = do
  pkgss <- getInstalledPackages' verbosity packagedbs conf
  checkPackageDbStack packagedbs
  let pkgs = concatMap snd pkgss
      -- On Windows, various fields have $topdir/foo rather than full
      -- paths. We need to substitute the right value in so that when
      -- we, for example, call gcc, we have proper paths to give it
      Just ghcProg = lookupProgram ghcProgram conf
      compilerDir  = takeDirectory (programPath ghcProg)
      topDir       = takeDirectory compilerDir
      pkgs'        = map (substTopDir topDir) pkgs
      pi1          = PackageIndex.fromList pkgs'
      rtsPackages  = lookupPackageName pi1 (PackageName "rts")
      rtsPackages' = map removeMingwIncludeDir rtsPackages
      pi2          = pi1 `merge` fromList rtsPackages'
  return pi2
getInstalledPackages :: Verbosity -> PackageDBStack -> ProgramConfiguration
                     -> IO (PackageIndex InstalledPackageInfo)
getInstalledPackages verbosity packagedbs conf = do
  pkgss <- getInstalledPackages' verbosity packagedbs conf
  checkPackageDbStack packagedbs
  let pkgs = concatMap snd pkgss
      -- On Windows, various fields have $topdir/foo rather than full
      -- paths. We need to substitute the right value in so that when
      -- we, for example, call gcc, we have proper paths to give it
      Just ghcProg = lookupProgram ghcProgram conf
      compilerDir  = takeDirectory (programPath ghcProg)
      topDir       = takeDirectory compilerDir
      pkgs'        = map (substTopDir topDir) pkgs
      pi1          = PackageIndex.fromList pkgs'
      rtsPackages  = lookupPackageName pi1 (PackageName "rts")
      rtsPackages' = map removeMingwIncludeDir rtsPackages
      pi2          = pi1 `merge` fromList rtsPackages'
  return pi2
getInstalledPackages verbosity packagedbs conf = do
  pkgss <- getInstalledPackages' verbosity packagedbs conf
  checkPackageDbStack packagedbs
  let pkgs = concatMap snd pkgss
      -- On Windows, various fields have $topdir/foo rather than full
      -- paths. We need to substitute the right value in so that when
      -- we, for example, call gcc, we have proper paths to give it
      Just ghcProg = lookupProgram ghcProgram conf
      compilerDir  = takeDirectory (programPath ghcProg)
      topDir       = takeDirectory compilerDir
      pkgs'        = map (substTopDir topDir) pkgs
      pi1          = PackageIndex.fromList pkgs'
      rtsPackages  = lookupPackageName pi1 (PackageName "rts")
      rtsPackages' = map removeMingwIncludeDir rtsPackages
      pi2          = pi1 `merge` fromList rtsPackages'
  return pi2