diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,34 +1,6 @@
-{-# LANGUAGE CPP #-}
-{-# OPTIONS_GHC -Wall #-}
-
-module Main ( main ) where
-
-#ifndef MIN_VERSION_cabal_doctest
-#define MIN_VERSION_cabal_doctest(x,y,z) 0
-#endif
-
-#if MIN_VERSION_cabal_doctest(1,0,0)
-
-import Distribution.Extra.Doctest ( defaultMainWithDoctests )
-main :: IO ()
-main = defaultMainWithDoctests "doctests"
-
-#else
-
-#ifdef MIN_VERSION_Cabal
--- If the macro is defined, we have new cabal-install,
--- but for some reason we don't have cabal-doctest in package-db
---
--- Probably we are running cabal sdist, when otherwise using new-build
--- workflow
-#warning You are configuring this package without cabal-doctest installed. \
-         The doctests test-suite will not work as a result. \
-         To fix this, install cabal-doctest before configuring.
-#endif
+module Main (main) where
 
 import Distribution.Simple
 
 main :: IO ()
 main = defaultMain
-
-#endif
diff --git a/cabal2nix.cabal b/cabal2nix.cabal
--- a/cabal2nix.cabal
+++ b/cabal2nix.cabal
@@ -1,9 +1,6 @@
 name:           cabal2nix
-version:        2.8
+version:        2.8.1
 synopsis:       Convert Cabal files into Nix build instructions.
-description:    Convert Cabal files into Nix build instructions. Users of Nix can install the latest version by running:
-                .
-                > nix-env -i cabal2nix
 category:       Distribution, Nix
 stability:      stable
 homepage:       https://github.com/nixos/cabal2nix#readme
@@ -75,10 +72,16 @@
 maintainer:     Peter Simons <simons@cryp.to>
 license:        BSD3
 license-file:   LICENSE
-tested-with:    GHC > 8.2 && < 8.3
-build-type:     Custom
-cabal-version:  >= 1.24
+tested-with:    GHC == 8.2.2
+build-type:     Simple
+cabal-version:  1.24
 
+description:
+  Convert Cabal files into Nix build instructions. Users of Nix can install the
+  latest version by running:
+  .
+  > nix-env -i cabal2nix
+
 extra-source-files:
     README.md
 
@@ -86,12 +89,6 @@
   type: git
   location: https://github.com/nixos/cabal2nix
 
-custom-setup
-  setup-depends:
-      Cabal
-    , base >=4 && <5
-    , cabal-doctest >=1 && <1.1
-
 library
   hs-source-dirs:
       src
@@ -110,7 +107,7 @@
     , filepath
     , hackage-db >2
     , hopenssl >=2
-    , hpack == 0.21.*
+    , hpack == 0.22.*
     , language-nix
     , lens
     , optparse-applicative
@@ -175,39 +172,4 @@
   other-modules:
       Paths_cabal2nix
       HackageGit
-  default-language: Haskell2010
-
-test-suite doctests
-  type: exitcode-stdio-1.0
-  main-is: doctests.hs
-  other-modules:
-      Paths_cabal2nix
-  hs-source-dirs:
-      test
-  ghc-options: -Wall -threaded
-  build-depends:
-      Cabal >2
-    , aeson
-    , ansi-wl-pprint
-    , base <5
-    , bytestring
-    , containers
-    , deepseq >=1.4
-    , directory
-    , distribution-nixpkgs >=1.1
-    , doctest
-    , filepath
-    , hackage-db >2
-    , hopenssl >=2
-    , hpack
-    , language-nix
-    , lens
-    , optparse-applicative
-    , pretty >=1.1.2
-    , process
-    , split
-    , text
-    , time
-    , transformers
-    , yaml
   default-language: Haskell2010
diff --git a/src/Cabal2nix.hs b/src/Cabal2nix.hs
--- a/src/Cabal2nix.hs
+++ b/src/Cabal2nix.hs
@@ -35,7 +35,7 @@
 import Paths_cabal2nix ( version )
 import System.Environment ( getArgs )
 import System.IO ( hFlush, hPutStrLn, stdout, stderr )
-import qualified Text.PrettyPrint.ANSI.Leijen as P2 hiding ( (<$>), (<>) )
+import qualified Text.PrettyPrint.ANSI.Leijen as P2
 import Text.PrettyPrint.HughesPJClass ( Doc, Pretty(..), text, vcat, hcat, semi )
 
 data Options = Options
@@ -176,7 +176,7 @@
                                             []
                                             (pkgCabal pkg)
               & src .~ pkgSource pkg
-              & subpath .~ (fromMaybe "." optSubpath)
+              & subpath .~ fromMaybe "." optSubpath
               & runHaddock .~ optHaddock
               & jailbreak .~ optJailbreak
               & hyperlinkSource .~ optHyperlinkSource
diff --git a/src/Distribution/Nixpkgs/Haskell/Derivation.hs b/src/Distribution/Nixpkgs/Haskell/Derivation.hs
--- a/src/Distribution/Nixpkgs/Haskell/Derivation.hs
+++ b/src/Distribution/Nixpkgs/Haskell/Derivation.hs
@@ -102,7 +102,7 @@
 instance NFData Derivation
 
 instance Pretty Derivation where
-  pPrint drv@(MkDerivation {..}) = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
+  pPrint drv@MkDerivation {..} = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
     [ text "mkDerivation" <+> lbrace
     , nest 2 $ vcat
       [ attr "pname"   $ doubleQuotes $ disp (packageName _pkgid)
@@ -143,7 +143,7 @@
       renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- _cabalFlags ]
                       ++ map text (toAscList _configureFlags)
       isHackagePackage = "mirror://hackage/" `isPrefixOf` derivUrl _src
-      sourceAttr (DerivationSource{..})
+      sourceAttr DerivationSource {..}
         | isHackagePackage = attr "sha256" $ string derivHash
         | derivKind /= "" = vcat
            [ text "src" <+> equals <+> text ("fetch" ++ derivKind) <+> lbrace
diff --git a/src/Distribution/Nixpkgs/Haskell/FromCabal.hs b/src/Distribution/Nixpkgs/Haskell/FromCabal.hs
--- a/src/Distribution/Nixpkgs/Haskell/FromCabal.hs
+++ b/src/Distribution/Nixpkgs/Haskell/FromCabal.hs
@@ -22,14 +22,14 @@
 import Distribution.Package
 import Distribution.PackageDescription
 import qualified Distribution.PackageDescription as Cabal
+import Distribution.PackageDescription.Configuration as Cabal
+import Distribution.System
+import Distribution.Text ( display )
+import Distribution.Types.ComponentRequestedSpec as Cabal
 import Distribution.Types.ExeDependency as Cabal
 import Distribution.Types.LegacyExeDependency as Cabal
 import Distribution.Types.PkgconfigDependency as Cabal
 import Distribution.Types.UnqualComponentName as Cabal
-import Distribution.PackageDescription.Configuration as Cabal
-import Distribution.Types.ComponentRequestedSpec as Cabal
-import Distribution.System
-import Distribution.Text ( display )
 import Distribution.Version
 import Language.Nix
 
@@ -42,7 +42,7 @@
     where
       (descr, missingDeps) = finalizeGenericPackageDescription haskellResolver arch compiler flags constraints genDesc
 
-finalizeGenericPackageDescription :: HaskellResolver -> Platform -> CompilerInfo ->  FlagAssignment -> [Constraint] -> GenericPackageDescription -> (PackageDescription, [Dependency])
+finalizeGenericPackageDescription :: HaskellResolver -> Platform -> CompilerInfo -> FlagAssignment -> [Constraint] -> GenericPackageDescription -> (PackageDescription, [Dependency])
 finalizeGenericPackageDescription haskellResolver arch compiler flags constraints genDesc =
   let
     -- We have to call the Cabal finalizer several times with different resolver
@@ -56,10 +56,17 @@
                           , benchmarksRequested = True
                           }
 
-    jailbrokenResolver :: HaskellResolver
-    jailbrokenResolver (Dependency pkg _) = haskellResolver (Dependency pkg anyVersion)
+    jailbroken :: HaskellResolver -> HaskellResolver
+    jailbroken resolver (Dependency pkg _) = resolver (Dependency pkg anyVersion)
 
-  in case finalize jailbrokenResolver of
+    withInternalLibs :: HaskellResolver -> HaskellResolver
+    withInternalLibs resolver d = depPkgName d `elem` internalNames || resolver d
+
+    internalNames :: [PackageName]
+    internalNames =    [ unqualComponentNameToPackageName n | (n,_) <- condSubLibraries genDesc ]
+                    ++ [ unqualComponentNameToPackageName n | Just n <- libName <$> subLibraries (packageDescription genDesc) ]
+
+  in case finalize (jailbroken (withInternalLibs haskellResolver)) of
     Left m -> case finalize (const True) of
                 Left _      -> error ("Cabal cannot finalize " ++ display (packageId genDesc))
                 Right (d,_) -> (d,m)
diff --git a/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs b/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs
--- a/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs
+++ b/src/Distribution/Nixpkgs/Haskell/FromCabal/Configuration.hs
@@ -97,7 +97,7 @@
   decodeFile path >>= maybe (fail ("invalid config file at " ++ show path)) assertConsistency
 
 assertConsistency :: Monad m => Configuration -> m Configuration
-assertConsistency cfg@(Configuration {..}) = do
+assertConsistency cfg@Configuration {..} = do
   let report msg = fail ("*** configuration error: " ++ msg)
 
       maintainedPackages = Set.unions (Map.elems packageMaintainers)
diff --git a/src/Distribution/Nixpkgs/Haskell/FromCabal/Flags.hs b/src/Distribution/Nixpkgs/Haskell/FromCabal/Flags.hs
--- a/src/Distribution/Nixpkgs/Haskell/FromCabal/Flags.hs
+++ b/src/Distribution/Nixpkgs/Haskell/FromCabal/Flags.hs
@@ -12,6 +12,7 @@
 configureCabalFlags (PackageIdentifier name version)
  | name == "accelerate-examples"= [disable "opencl"]
  | name == "arithmoi"           = [disable "llvm"]
+ | name == "cabal-plan"         = [enable "exe"]
  | name == "cassava"            = [disable "bytestring--lt-0_10_4"]
  | name == "darcs"              = [enable "library", enable "force-char8-encoding"]
  | name == "diagrams-builder"   = [enable "cairo", enable "svg", enable "ps", enable "rasterific"]
@@ -43,7 +44,7 @@
                                 = [enable "externalLibsass"]
  | name == "hmatrix"            = [enable "openblas", enable "disable-default-paths"]
  | name == "hslua"              = [enable "system-lua"]
- | name == "idris"              = [enable "gmp", enable "ffi", enable "curses", ("execonly", version `withinRange` (orLaterVersion (mkVersion [1,1,1]))) ]
+ | name == "idris"              = [enable "gmp", enable "ffi", enable "curses", ("execonly", version `withinRange` orLaterVersion (mkVersion [1,1,1])) ]
  | name == "io-streams"         = [enable "NoInteractiveTests"]
  | name == "liquid-fixpoint"    = [enable "build-external"]
  | name == "pandoc"             = [enable "https", disable "trypandoc"]
diff --git a/src/Distribution/Nixpkgs/Haskell/FromCabal/Name.hs b/src/Distribution/Nixpkgs/Haskell/FromCabal/Name.hs
--- a/src/Distribution/Nixpkgs/Haskell/FromCabal/Name.hs
+++ b/src/Distribution/Nixpkgs/Haskell/FromCabal/Name.hs
@@ -175,6 +175,7 @@
 buildToolNixName :: String -> [Identifier]
 buildToolNixName ""                             = return (error "buildToolNixName: invalid empty dependency name")
 buildToolNixName "cabal"                        = return "cabal-install"
+buildToolNixName "fltk-config"                  = return "fltk"
 buildToolNixName "ghc"                          = []
 buildToolNixName "gtk2hsC2hs"                   = return "gtk2hs-buildtools"
 buildToolNixName "gtk2hsHookGenerator"          = return "gtk2hs-buildtools"
@@ -182,9 +183,9 @@
 buildToolNixName "hsc2hs"                       = []
 buildToolNixName "nix-build"                    = return "nix"
 buildToolNixName "nix-env"                      = return "nix"
+buildToolNixName "nix-hash"                     = return "nix"
 buildToolNixName "nix-instantiate"              = return "nix"
 buildToolNixName "nix-store"                    = return "nix"
-buildToolNixName "fltk-config"                  = return "fltk"
 buildToolNixName x                              = return (fromString x)
 
 -- | Helper function to extract the package name from a String that may or may
diff --git a/src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs b/src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs
--- a/src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs
+++ b/src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs
@@ -33,7 +33,7 @@
 normalizeMeta meta = meta
   & description %~ normalizeSynopsis
   & platforms %~ Set.intersection allKnownPlatforms
-  & hydraPlatforms %~ Set.intersection (meta^.platforms)
+  & hydraPlatforms %~ (if meta^.broken then const Set.empty else Set.intersection (meta^.platforms))
 
 normalizeSynopsis :: String -> String
 normalizeSynopsis desc
@@ -58,5 +58,5 @@
   sortBy (compare `on` fst) $
     reverse $
       nubBy ((==) `on` fst) $
-        reverse $
+        reverse
           [ (mkFlagName (lowercase (unFlagName n)), b) | (n, b) <- flags ]
diff --git a/src/Distribution/Nixpkgs/Haskell/Hackage.hs b/src/Distribution/Nixpkgs/Haskell/Hackage.hs
--- a/src/Distribution/Nixpkgs/Haskell/Hackage.hs
+++ b/src/Distribution/Nixpkgs/Haskell/Hackage.hs
@@ -32,7 +32,7 @@
   return (mapWithKey (parsePackageData dbu) dbp)
 
 parsePackageData :: U.HackageDB -> PackageName -> P.PackageData -> PackageData
-parsePackageData dbu pn pd = mapWithKey (parseVersionData (dbu ! pn)) pd
+parsePackageData dbu pn = mapWithKey (parseVersionData (dbu ! pn))
 
 parseVersionData :: U.PackageData -> Version -> P.VersionData -> VersionData
 parseVersionData pdu v vd = VersionData
diff --git a/src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs b/src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs
--- a/src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs
+++ b/src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs
@@ -42,8 +42,8 @@
            -- ^ If we have hackage-snapshot time.
            -> Source
            -> IO Package
-getPackage optHpack optHackageDB optHackageSnapshot source = do
-  getPackage' optHpack (loadHackageDB optHackageDB optHackageSnapshot) source
+getPackage optHpack optHackageDB optHackageSnapshot =
+  getPackage' optHpack (loadHackageDB optHackageDB optHackageSnapshot)
 
 getPackage' :: Bool
             -- ^ Whether hpack should regenerate the cabal file.
@@ -67,7 +67,7 @@
     r <- fetch (\dir -> cabalFromPath optHpack (dir </> sourceCabalDir src)) src
     case r of
       Nothing -> fail "Failed to fetch source. Does the URL exist?"
-      Just (derivSource, (externalSource, ranHpack, pkgDesc)) -> do
+      Just (derivSource, (externalSource, ranHpack, pkgDesc)) ->
         return (derivSource <$ guard externalSource, ranHpack, pkgDesc)
 
 loadHackageDB :: Maybe FilePath
@@ -191,10 +191,10 @@
 
 hpackDirectory :: FilePath -> MaybeT IO (Bool, Cabal.GenericPackageDescription)
 hpackDirectory dir = do
-  mPackage <- liftIO $ Hpack.readPackageConfig $ dir </> "package.yaml"
+  mPackage <- liftIO $ Hpack.readPackageConfig "" $ dir </> "package.yaml"
   case mPackage of
     Left err -> liftIO $ hPutStrLn stderr ("*** hpack error: " ++ show err ++ ". Exiting.") >> exitFailure
-    Right (_, pkg') -> do
+    Right (pkg', _) -> do
       let hpackOutput = Hpack.renderPackage Hpack.defaultRenderSettings 2 [] [] pkg'
           hash = printSHA256 $ digestString (digestByName "sha256") hpackOutput
       case parseGenericPackageDescription hpackOutput of
diff --git a/test/doctests.hs b/test/doctests.hs
deleted file mode 100644
--- a/test/doctests.hs
+++ /dev/null
@@ -1,10 +0,0 @@
-module Main where
-
-import Build_doctests (flags, pkgs, module_sources)
-import Data.Foldable (traverse_)
-import Test.DocTest (doctest)
-
-main :: IO ()
-main = do let args = flags ++ pkgs ++ module_sources
-          traverse_ putStrLn args -- optionally print arguments
-          doctest args
