diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@
 This derivation will not fetch from hackage, but instead use the directory which
 contains the derivation as the source repository.
 
-`cabal2nix` currently supports the following respository types:
+`cabal2nix` currently supports the following repository types:
 
 * directory
 * source archive (zip, tar.gz, ...) from http or https URL or local file.
diff --git a/cabal2nix.cabal b/cabal2nix.cabal
--- a/cabal2nix.cabal
+++ b/cabal2nix.cabal
@@ -3,7 +3,7 @@
 -- see: https://github.com/sol/hpack
 
 name:           cabal2nix
-version:        2.3.1
+version:        2.4
 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:
                 .
@@ -66,7 +66,7 @@
 maintainer:     Peter Simons <simons@cryp.to>
 license:        BSD3
 license-file:   LICENSE
-tested-with:    GHC > 7.10 && < 8.1
+tested-with:    GHC > 7.10 && < 8.3
 build-type:     Custom
 cabal-version:  >= 1.10
 
@@ -93,7 +93,7 @@
     , ansi-wl-pprint
     , base < 5
     , bytestring
-    , Cabal > 1.24
+    , Cabal > 2
     , containers
     , deepseq >= 1.4
     , directory
@@ -141,7 +141,7 @@
     , ansi-wl-pprint
     , base < 5
     , bytestring
-    , Cabal > 1.24
+    , Cabal > 2
     , containers
     , deepseq >= 1.4
     , directory
@@ -173,7 +173,7 @@
     , ansi-wl-pprint
     , base < 5
     , bytestring
-    , Cabal > 1.24
+    , Cabal > 2
     , containers
     , deepseq >= 1.4
     , directory
@@ -212,7 +212,7 @@
     , ansi-wl-pprint
     , base < 5
     , bytestring
-    , Cabal > 1.24
+    , Cabal > 2
     , containers
     , deepseq >= 1.4
     , directory
diff --git a/hackage2nix/HackageGit.hs b/hackage2nix/HackageGit.hs
--- a/hackage2nix/HackageGit.hs
+++ b/hackage2nix/HackageGit.hs
@@ -16,7 +16,7 @@
 import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
 import Distribution.Package
 import Distribution.PackageDescription
-import Distribution.PackageDescription.Parse ( parsePackageDescription, ParseResult(..) )
+import Distribution.PackageDescription.Parse ( parseGenericPackageDescription, ParseResult(..) )
 import Distribution.Text
 import Distribution.Version
 import OpenSSL.Digest ( digest, digestByName )
@@ -31,7 +31,7 @@
     discoverPackageVersions :: Hackage -> String -> IO Hackage
     discoverPackageVersions db pkg = do
       vs <- getSubDirs (path </> pkg)
-      return (Map.insert (PackageName pkg) (Set.fromList (Prelude.map fromString vs)) db)
+      return (Map.insert (mkPackageName pkg) (Set.fromList (Prelude.map fromString vs)) db)
 
 getSubDirs :: FilePath -> IO [FilePath]
 getSubDirs path = do
@@ -47,7 +47,7 @@
 readPackage dirPrefix (PackageIdentifier name version) = do
   let cabalFile = dirPrefix </> unPackageName name </> display version </> unPackageName name <.> "cabal"
   buf <- BS.readFile cabalFile
-  cabal <- case parsePackageDescription (decodeUTF8 buf) of
+  cabal <- case parseGenericPackageDescription (decodeUTF8 buf) of
              ParseOk _ a  -> return a
              ParseFailed err -> fail (cabalFile ++ ": " ++ show err)
   return (cabal, printSHA256 (digest (digestByName "sha256") buf))
diff --git a/hackage2nix/Main.hs b/hackage2nix/Main.hs
--- a/hackage2nix/Main.hs
+++ b/hackage2nix/Main.hs
@@ -78,8 +78,9 @@
             . Map.delete "som"                  -- TODO: https://github.com/NixOS/cabal2nix/issues/164
             . Map.delete "type"                 -- TODO: https://github.com/NixOS/cabal2nix/issues/163
             . Map.delete "control-invariants"   -- TODO: depends on "assert"
-            . over (at ("hermes")) ((fmap (set (contains "1.3.4.3") False)))            -- TODO: https://github.com/haskell/hackage-server/issues/436
-            . over (at ("gogol-admin-reports")) ((fmap (set (contains "0.2.0") False))) -- TODO: https://github.com/commercialhaskell/all-cabal-hashes/issues/11
+            . over (at ("hermes")) ((fmap (set (contains "1.3.4.3") False)))                  -- TODO: https://github.com/haskell/hackage-server/issues/436
+            . over (at ("gogol-admin-reports")) ((fmap (set (contains "0.2.0") False)))       -- TODO: https://github.com/commercialhaskell/all-cabal-hashes/issues/11
+            . over (at ("wai-middleware-prometheus")) ((fmap (set (contains "0.2.0") False))) -- TODO: https://github.com/commercialhaskell/all-cabal-hashes/issues/15
   hackage <- fixup <$> readHackage hackageRepository
   let
       hackagePackagesFile :: FilePath
@@ -200,4 +201,4 @@
   | otherwise                   = Nothing
 
 mangle :: PackageIdentifier -> String
-mangle (PackageIdentifier (PackageName name) v) = name ++ '_' : [ if c == '.' then '_' else c | c <- display v ]
+mangle (PackageIdentifier name v) = unPackageName name ++ '_' : [ if c == '.' then '_' else c | c <- display v ]
diff --git a/src/Cabal2nix.hs b/src/Cabal2nix.hs
--- a/src/Cabal2nix.hs
+++ b/src/Cabal2nix.hs
@@ -2,7 +2,7 @@
 {-# LANGUAGE OverloadedStrings #-}
 
 module Cabal2nix
-  ( main, cabal2nix
+  ( main, cabal2nix, cabal2nix'
   )
   where
 
@@ -19,7 +19,7 @@
 import Distribution.Nixpkgs.Haskell.FromCabal
 import Distribution.Nixpkgs.Haskell.PackageSourceSpec
 import Distribution.Nixpkgs.Meta
-import Distribution.PackageDescription ( FlagName(..), FlagAssignment )
+import Distribution.PackageDescription ( mkFlagName, FlagAssignment )
 import Distribution.Simple.Utils ( lowercase )
 import Distribution.System
 import Distribution.Text
@@ -34,7 +34,7 @@
 data Options = Options
   { optSha256 :: Maybe String
   , optMaintainer :: [String]
---, optPlatform :: [String]                                         -- TODO: fix command line handling of platforms
+--, optPlatform :: [String]       -- TODO: fix command line handling of platforms
   , optHaddock :: Bool
   , optDoCheck :: Bool
   , optJailbreak :: Bool
@@ -108,7 +108,7 @@
                      , P2.fillSep (map P2.text (words (  "If the URI refers to a cabal file, information for building the package "
                                                       ++ "will be retrieved from that file, but hackage will be used as a source "
                                                       ++ "for the derivation. Otherwise, the supplied URI will be used to as the "
-                                                      ++ "souce for the derivation and the information is taken from the cabal file "
+                                                      ++ "source for the derivation and the information is taken from the cabal file "
                                                       ++ "at the root of the downloaded source."
                                                       )))
                      ]))
@@ -118,8 +118,8 @@
 main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() ->
   cabal2nix =<< getArgs
 
-cabal2nix :: [String] -> IO ()
-cabal2nix args = do
+cabal2nix' :: [String] -> IO (Either Doc Derivation)
+cabal2nix' args = do
   Options {..} <- handleParseResult $ execParserPure defaultPrefs pinfo args
 
   pkg <- getPackage optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
@@ -165,10 +165,16 @@
               , text ""
               , text "  if pkgs.lib.inNixShell then drv.env else drv"
               ]
+  pure $ if optNixShellOutput then Left shell else Right deriv
 
-  print (if optNixShellOutput then shell else pPrint deriv)
+cabal2nix :: [String] -> IO ()
+cabal2nix args = do
+  v <- cabal2nix' args
+  print $ case v of
+    Left shell -> shell
+    Right d -> pPrint d
 
 readFlagList :: [String] -> FlagAssignment
 readFlagList = map tagWithValue
-  where tagWithValue ('-':fname) = (FlagName (lowercase fname), False)
-        tagWithValue fname       = (FlagName (lowercase fname), True)
+  where tagWithValue ('-':fname) = (mkFlagName (lowercase fname), False)
+        tagWithValue fname       = (mkFlagName (lowercase fname), True)
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
@@ -8,7 +8,7 @@
   , extraFunctionArgs, libraryDepends, executableDepends, testDepends, configureFlags
   , cabalFlags, runHaddock, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
   , enableLibraryProfiling, enableExecutableProfiling, phaseOverrides, editedCabalFile, metaSection
-  , dependencies, setupDepends, benchmarkDepends
+  , dependencies, setupDepends, benchmarkDepends, enableSeparateDataOutput
   )
   where
 
@@ -23,7 +23,7 @@
 import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
 import Distribution.Nixpkgs.Meta
 import Distribution.Package
-import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
+import Distribution.PackageDescription ( FlagAssignment, unFlagName )
 import GHC.Generics ( Generic )
 import Language.Nix
 import Language.Nix.PrettyPrinting
@@ -57,6 +57,7 @@
   , _enableSplitObjs            :: Bool
   , _phaseOverrides             :: String
   , _editedCabalFile            :: String
+  , _enableSeparateDataOutput   :: Bool
   , _metaSection                :: Meta
   }
   deriving (Show, Eq, Generic)
@@ -87,6 +88,7 @@
   , _enableSplitObjs = error "undefined Derivation.enableSplitObjs"
   , _phaseOverrides = error "undefined Derivation.phaseOverrides"
   , _editedCabalFile = error "undefined Derivation.editedCabalFile"
+  , _enableSeparateDataOutput = error "undefined Derivation.enableSeparateDataOutput"
   , _metaSection = error "undefined Derivation.metaSection"
   }
 
@@ -112,6 +114,7 @@
       , listattr "configureFlags" empty (map (show . show) renderedFlags)
       , boolattr "isLibrary" (not _isLibrary || _isExecutable) _isLibrary
       , boolattr "isExecutable" (not _isLibrary || _isExecutable) _isExecutable
+      , boolattr "enableSeparateDataOutput" _enableSeparateDataOutput _enableSeparateDataOutput
       , onlyIf (_setupDepends /= mempty) $ pPrintBuildInfo "setup" _setupDepends
       , onlyIf (_libraryDepends /= mempty) $ pPrintBuildInfo "library" _libraryDepends
       , onlyIf (_executableDepends /= mempty) $ pPrintBuildInfo "executable" _executableDepends
@@ -137,7 +140,7 @@
                           , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
                           ]
 
-      renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- _cabalFlags ]
+      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{..})
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
@@ -7,7 +7,6 @@
   )
   where
 
-import Control.Arrow ( second )
 import Control.Lens
 import Data.Maybe
 import Data.Set ( Set )
@@ -24,7 +23,10 @@
 import Distribution.Package
 import Distribution.PackageDescription
 import qualified Distribution.PackageDescription as Cabal
-import Distribution.PackageDescription.Configuration
+import Distribution.Types.LegacyExeDependency as Cabal
+import Distribution.Types.PkgconfigDependency as Cabal
+import Distribution.PackageDescription.Configuration as Cabal
+import Distribution.Types.ComponentRequestedSpec as Cabal
 import Distribution.System
 import Distribution.Text ( display )
 import Distribution.Version
@@ -40,8 +42,14 @@
       -- We have to call the Cabal finalizer several times with different resolver
       -- functions, and this convenience function makes our code shorter.
       finalize :: HaskellResolver -> Either [Dependency] (PackageDescription,FlagAssignment)
-      finalize resolver = finalizePackageDescription flags resolver arch compiler constraints (enableBenchmarks (enableTests genDesc))
+      finalize resolver = finalizePD flags requestedComponents resolver arch compiler constraints genDesc
 
+      requestedComponents :: ComponentRequestedSpec
+      requestedComponents = defaultComponentRequestedSpec
+                            { testsRequested      = True
+                            , benchmarksRequested = True
+                            }
+
       descr :: PackageDescription; missingDeps :: [Dependency]
       (descr,missingDeps) = case finalize jailbrokenResolver of
                               Left m -> case finalize (const True) of
@@ -75,6 +83,7 @@
     & enableSplitObjs .~ True
     & enableLibraryProfiling .~ False
     & enableExecutableProfiling .~ False
+    & enableSeparateDataOutput .~ not (null dataFiles)
     & subpath .~ "."
     & phaseOverrides .~ mempty
     & editedCabalFile .~ (if xrev > 0
@@ -93,7 +102,7 @@
     xrev = maybe 0 read (lookup "x-revision" customFieldsPD)
 
     resolveInHackage :: Identifier -> Binding
-    resolveInHackage i | (i^.ident) `elem` [ n | (Dependency (PackageName n) _) <- missingDeps ] = bindNull i
+    resolveInHackage i | (i^.ident) `elem` [ unPackageName n | (Dependency n _) <- missingDeps ] = bindNull i
                        | otherwise = binding # (i, path # ["self",i])   -- TODO: "self" shouldn't be hardcoded.
 
     goodScopes :: Set [Identifier]
@@ -109,15 +118,15 @@
       | otherwise                        = bindNull i
 
     resolveInHackageThenNixpkgs :: Identifier -> Binding
-    resolveInHackageThenNixpkgs i | haskellResolver (Dependency (PackageName (i^.ident)) anyVersion) = resolveInHackage i
+    resolveInHackageThenNixpkgs i | haskellResolver (Dependency (mkPackageName (i^.ident)) anyVersion) = resolveInHackage i
                                   | otherwise = resolveInNixpkgs i
 
     convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
     convertBuildInfo Cabal.BuildInfo {..} = mempty
       & haskell .~ Set.fromList [ resolveInHackage (toNixName x) | (Dependency x _) <- targetBuildDepends ]
       & system .~ Set.fromList [ resolveInNixpkgs y | x <- extraLibs, y <- libNixName x ]
-      & pkgconfig .~ Set.fromList [ resolveInNixpkgs y | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x ]
-      & tool .~ Set.fromList [ resolveInHackageThenNixpkgs y | Dependency (PackageName x) _ <- buildTools, y <- buildToolNixName x ]
+      & pkgconfig .~ Set.fromList [ resolveInNixpkgs y | PkgconfigDependency x _ <- pkgconfigDepends, y <- libNixName (unPkgconfigName x) ]
+      & tool .~ Set.fromList [ resolveInHackageThenNixpkgs y | LegacyExeDependency x _ <- buildTools, y <- buildToolNixName x ]
 
     convertSetupBuildInfo :: Cabal.SetupBuildInfo -> Nix.BuildInfo
     convertSetupBuildInfo bi = mempty
@@ -125,21 +134,3 @@
 
 bindNull :: Identifier -> Binding
 bindNull i = binding # (i, path # ["null"])
-
-enableTests :: GenericPackageDescription -> GenericPackageDescription
-enableTests gd = gd { condTestSuites = flaggedTests }
-  where
-    flaggedTests :: [(String, CondTree ConfVar [Dependency] TestSuite)]
-    flaggedTests = map (second (mapTreeData enableTest)) (condTestSuites gd)
-
-    enableTest :: TestSuite -> TestSuite
-    enableTest t = t { testEnabled = True }
-
-enableBenchmarks :: GenericPackageDescription -> GenericPackageDescription
-enableBenchmarks gd = gd { condBenchmarks = flaggedBenchmarks }
-  where
-    flaggedBenchmarks :: [(String, CondTree ConfVar [Dependency] Benchmark)]
-    flaggedBenchmarks = map (second (mapTreeData enableBenchmark)) (condBenchmarks gd)
-
-    enableBenchmark :: Benchmark -> Benchmark
-    enableBenchmark t = t { benchmarkEnabled = True }
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
@@ -1,11 +1,15 @@
+{-# LANGUAGE OverloadedStrings #-}
+
 module Distribution.Nixpkgs.Haskell.FromCabal.Flags ( configureCabalFlags ) where
 
+import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
+
 import Distribution.Package
 import Distribution.PackageDescription
-import Data.Version
+import Distribution.Version
 
 configureCabalFlags :: PackageIdentifier -> FlagAssignment
-configureCabalFlags (PackageIdentifier (PackageName name) version)
+configureCabalFlags (PackageIdentifier name version)
  | name == "accelerate-examples"= [disable "opencl"]
  | name == "arithmoi"           = [disable "llvm"]
  | name == "darcs"              = [enable "library", enable "force-char8-encoding"]
@@ -34,7 +38,7 @@
  | name == "haskeline"          = [enable "terminfo"]
  | name == "haste-compiler"     = [enable "portable"]
  | name == "highlighting-kate"  = [enable "pcre-light"]
- | name == "hlibsass" && version >= Version [0,1,5] []
+ | name == "hlibsass" && version >= mkVersion [0,1,5]
                                 = [enable "externalLibsass"]
  | name == "hmatrix"            = [enable "openblas"]
  | name == "hslua"              = [enable "system-lua"]
@@ -51,7 +55,7 @@
  | otherwise                    = []
 
 enable :: String -> (FlagName,Bool)
-enable name = (FlagName name, True)
+enable name = (mkFlagName name, True)
 
 disable :: String -> (FlagName,Bool)
-disable name = (FlagName name, False)
+disable name = (mkFlagName name, False)
diff --git a/src/Distribution/Nixpkgs/Haskell/FromCabal/License.hs b/src/Distribution/Nixpkgs/Haskell/FromCabal/License.hs
--- a/src/Distribution/Nixpkgs/Haskell/FromCabal/License.hs
+++ b/src/Distribution/Nixpkgs/Haskell/FromCabal/License.hs
@@ -1,37 +1,39 @@
+{-# LANGUAGE ViewPatterns #-}
+
 module Distribution.Nixpkgs.Haskell.FromCabal.License ( fromCabalLicense ) where
 
 import Distribution.Nixpkgs.License
 import Distribution.License ( License(..), knownLicenses )
 import Distribution.Text (display)
 import Data.List (intercalate)
-import Data.Version
+import Distribution.Version
 
 -- TODO: Programatically strip trailing zeros from license version numbers.
 
 fromCabalLicense :: Distribution.License.License -> Distribution.Nixpkgs.License.License
-fromCabalLicense (GPL Nothing)                          = Unknown (Just "GPL")
-fromCabalLicense (GPL (Just (Version [2] [])))          = Known "stdenv.lib.licenses.gpl2"
-fromCabalLicense (GPL (Just (Version [3] [])))          = Known "stdenv.lib.licenses.gpl3"
-fromCabalLicense (GPL (Just (Version [3,0] [])))        = Known "stdenv.lib.licenses.gpl3"
-fromCabalLicense (LGPL Nothing)                         = Unknown (Just "LGPL")
-fromCabalLicense (LGPL (Just (Version [2,1] [])))       = Known "stdenv.lib.licenses.lgpl21"
-fromCabalLicense (LGPL (Just (Version [2] [])))         = Known "stdenv.lib.licenses.lgpl2"
-fromCabalLicense (LGPL (Just (Version [3] [])))         = Known "stdenv.lib.licenses.lgpl3"
-fromCabalLicense (LGPL (Just (Version [3,0] [])))       = Known "stdenv.lib.licenses.lgpl3"
-fromCabalLicense (AGPL Nothing)                         = Unknown (Just "AGPL")
-fromCabalLicense (AGPL (Just (Version [3] [])))         = Known "stdenv.lib.licenses.agpl3"
-fromCabalLicense (AGPL (Just (Version [3,0] [])))       = Known "stdenv.lib.licenses.agpl3"
-fromCabalLicense (MPL (Version [2,0] []))               = Known "stdenv.lib.licenses.mpl20"
-fromCabalLicense BSD2                                   = Known "stdenv.lib.licenses.bsd2"
-fromCabalLicense BSD3                                   = Known "stdenv.lib.licenses.bsd3"
-fromCabalLicense BSD4                                   = Known "stdenv.lib.licenses.bsdOriginal"
-fromCabalLicense MIT                                    = Known "stdenv.lib.licenses.mit"
-fromCabalLicense PublicDomain                           = Known "stdenv.lib.licenses.publicDomain"
-fromCabalLicense UnspecifiedLicense                     = Known "stdenv.lib.licenses.unfree"
-fromCabalLicense AllRightsReserved                      = Known "stdenv.lib.licenses.unfree"
-fromCabalLicense (Apache Nothing)                       = Known "stdenv.lib.licenses.asl20"
-fromCabalLicense (Apache (Just (Version [2,0] [])))     = Known "stdenv.lib.licenses.asl20"
-fromCabalLicense ISC                                    = Known "stdenv.lib.licenses.isc"
-fromCabalLicense OtherLicense                           = Unknown Nothing
-fromCabalLicense l                                      = error $ "Distribution.Nixpkgs.Haskell.FromCabal.License.fromCabalLicense: unknown license"
-                                                            ++ show l ++"\nChoose one of: " ++ intercalate ", " (map display knownLicenses)
+fromCabalLicense (GPL Nothing)                             = Unknown (Just "GPL")
+fromCabalLicense (GPL (Just (versionNumbers -> [2])))      = Known "stdenv.lib.licenses.gpl2"
+fromCabalLicense (GPL (Just (versionNumbers -> [3])))      = Known "stdenv.lib.licenses.gpl3"
+fromCabalLicense (GPL (Just (versionNumbers -> [3,0])))    = Known "stdenv.lib.licenses.gpl3"
+fromCabalLicense (LGPL Nothing)                            = Unknown (Just "LGPL")
+fromCabalLicense (LGPL (Just (versionNumbers -> [2,1])))   = Known "stdenv.lib.licenses.lgpl21"
+fromCabalLicense (LGPL (Just (versionNumbers -> [2])))     = Known "stdenv.lib.licenses.lgpl2"
+fromCabalLicense (LGPL (Just (versionNumbers -> [3])))     = Known "stdenv.lib.licenses.lgpl3"
+fromCabalLicense (LGPL (Just (versionNumbers -> [3,0])))   = Known "stdenv.lib.licenses.lgpl3"
+fromCabalLicense (AGPL Nothing)                            = Unknown (Just "AGPL")
+fromCabalLicense (AGPL (Just (versionNumbers -> [3])))     = Known "stdenv.lib.licenses.agpl3"
+fromCabalLicense (AGPL (Just (versionNumbers -> [3,0])))   = Known "stdenv.lib.licenses.agpl3"
+fromCabalLicense (MPL (versionNumbers ->  [2,0]))          = Known "stdenv.lib.licenses.mpl20"
+fromCabalLicense BSD2                                      = Known "stdenv.lib.licenses.bsd2"
+fromCabalLicense BSD3                                      = Known "stdenv.lib.licenses.bsd3"
+fromCabalLicense BSD4                                      = Known "stdenv.lib.licenses.bsdOriginal"
+fromCabalLicense MIT                                       = Known "stdenv.lib.licenses.mit"
+fromCabalLicense PublicDomain                              = Known "stdenv.lib.licenses.publicDomain"
+fromCabalLicense UnspecifiedLicense                        = Known "stdenv.lib.licenses.unfree"
+fromCabalLicense AllRightsReserved                         = Known "stdenv.lib.licenses.unfree"
+fromCabalLicense (Apache Nothing)                          = Known "stdenv.lib.licenses.asl20"
+fromCabalLicense (Apache (Just (versionNumbers -> [2,0]))) = Known "stdenv.lib.licenses.asl20"
+fromCabalLicense ISC                                       = Known "stdenv.lib.licenses.isc"
+fromCabalLicense OtherLicense                              = Unknown Nothing
+fromCabalLicense l                                         = error $ "Distribution.Nixpkgs.Haskell.FromCabal.License.fromCabalLicense: unknown license"
+                                                                  ++ show l ++"\nChoose one of: " ++ intercalate ", " (map display knownLicenses)
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
@@ -10,8 +10,8 @@
 
 -- | Map Cabal names to Nix attribute names.
 toNixName :: PackageName -> Identifier
-toNixName (PackageName "") = error "toNixName: invalid empty package name"
-toNixName (PackageName n)  = fromString n
+toNixName "" = error "toNixName: invalid empty package name"
+toNixName n  = fromString (unPackageName n)
 
 -- | Map library names specified in Cabal files to Nix package identifiers.
 --
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
@@ -1,3 +1,5 @@
+{-# LANGUAGE OverloadedStrings #-}
+
 module Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalize, normalizeCabalFlags ) where
 
 import Control.Lens
@@ -8,7 +10,7 @@
 import Distribution.Nixpkgs.Haskell
 import Distribution.Nixpkgs.Meta
 import Distribution.Package
-import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
+import Distribution.PackageDescription ( FlagAssignment, mkFlagName, unFlagName )
 import Distribution.Simple.Utils ( lowercase )
 import Language.Nix hiding ( quote )
 
@@ -20,12 +22,12 @@
   & over benchmarkDepends (normalizeBuildInfo (packageName drv))
   & over metaSection normalizeMeta
   & over cabalFlags normalizeCabalFlags
-  & jailbreak %~ (&& (packageName drv /= PackageName "jailbreak-cabal"))
+  & jailbreak %~ (&& (packageName drv /= "jailbreak-cabal"))
 
 normalizeBuildInfo :: PackageName -> BuildInfo -> BuildInfo
-normalizeBuildInfo (PackageName pname) bi = bi
-  & haskell %~ Set.filter (\b -> view localName b /= fromString pname)
-  & tool %~ Set.filter (\b -> view localName b /= fromString pname)
+normalizeBuildInfo pname bi = bi
+  & haskell %~ Set.filter (\b -> view localName b /= fromString (unPackageName pname))
+  & tool %~ Set.filter (\b -> view localName b /= fromString (unPackageName pname))
 
 normalizeMeta :: Meta -> Meta
 normalizeMeta meta = meta
@@ -45,14 +47,14 @@
 quote (c:cs)      = c : quote cs
 quote []          = []
 
--- |When a flag is specified multiple times, the first occurrence
--- counts. This is counter-intuitive, IMHO, but it's how cabal does it.
--- Flag names are spelled in all lowercase.
+-- | When a flag is specified multiple times, the first occurrence counts. This
+-- is counter-intuitive, IMHO, but it's how cabal does it. Flag names are
+-- spelled in all lowercase.
 --
--- >>> normalizeCabalFlags [(FlagName "foo", True), (FlagName "FOO", True), (FlagName "Foo", False)]
+-- >>> normalizeCabalFlags [(mkFlagName "foo", True), (mkFlagName "FOO", True), (mkFlagName "Foo", False)]
 -- [(FlagName "foo",True)]
 
 normalizeCabalFlags :: FlagAssignment -> FlagAssignment
 normalizeCabalFlags flags' = nubBy ((==) `on` fst) (sortBy (compare `on` fst) flags)
   where
-    flags = [ (FlagName (lowercase n), b) | (FlagName n, b) <- flags' ]
+    flags = [ (mkFlagName (lowercase (unFlagName n)), b) | (n, b) <- flags' ]
diff --git a/src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs b/src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs
--- a/src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs
+++ b/src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs
@@ -27,7 +27,7 @@
     collidesWithHaskellName b = view localName b `Set.member` buildDeps
 
     myName :: Identifier
-    myName = ident # n where PackageName n = packageName drv
+    myName = ident # unPackageName (packageName drv)
 
     buildDeps :: Set Identifier
     buildDeps = Set.delete myName (setOf (dependencies . haskell . folded . localName) drv)
@@ -89,6 +89,7 @@
   , ("libconfig", over (libraryDepends . system) (replace "config = null" (pkg "libconfig")))
   , ("liquid-fixpoint", set (executableDepends . system . contains (pkg "ocaml")) True . set (testDepends . system . contains (pkg "z3")) True)
   , ("liquidhaskell", set (testDepends . system . contains (pkg "z3")) True)
+  , ("lzma-clib", over (metaSection . platforms) (Set.filter (\(Platform _  os) -> os == Windows)) . set (libraryDepends . haskell . contains (bind "self.only-buildable-on-windows")) False)
   , ("MFlow < 4.6", set (libraryDepends . tool . contains (bind "self.cpphs")) True)
   , ("mwc-random", set doCheck False)
   , ("mysql", set (libraryDepends . system . contains (pkg "mysql")) True)
@@ -104,7 +105,6 @@
   , ("readline", over (libraryDepends . system) (Set.union (pkgs ["readline", "ncurses"])))
   , ("sdr", over (metaSection . platforms) (Set.filter (\(Platform arch _) -> arch == X86_64))) -- https://github.com/adamwalker/sdr/issues/2
   , ("shake-language-c", set doCheck False) -- https://github.com/samplecount/shake-language-c/issues/26
-  , ("sharc-timbre", set (metaSection . broken) True) -- The build takes insanely long, i.e. >8 hours.
   , ("ssh", set doCheck False) -- test suite runs forever, probably can't deal with our lack of network access
   , ("stack", set phaseOverrides stackOverrides . set doCheck False)
   , ("stripe-http-streams", set doCheck False . set (metaSection . broken) False)
@@ -225,8 +225,9 @@
 xmonadPostInstall = unlines
   [ "postInstall = ''"
   , "  shopt -s globstar"
-  , "  mkdir -p $out/share/man/man1"
-  , "  mv \"$out/\"**\"/man/\"*.1 $out/share/man/man1/"
+  , "  mkdir -p $doc/share/man/man1"
+  , "  mv \"$data/\"**\"/man/\"*[0-9] $doc/share/man/man1/"
+  , "  rm \"$data/\"**\"/man/\"*"
   , "'';"
   ]
 
@@ -287,8 +288,8 @@
   . over (libraryDepends . haskell) (Set.union (Set.fromList (map bind ["self.base", "self.cereal", "self.mtl", "self.text", "self.bytestring"])))
 
 webkitgtk24xHook :: Derivation -> Derivation    -- https://github.com/NixOS/cabal2nix/issues/145
-webkitgtk24xHook = set (libraryDepends . pkgconfig . contains (pkg "webkitgtk24x")) True
-                 . over (libraryDepends . pkgconfig) (Set.filter (\b -> view localName b /= "webkitgtk24x"))
+webkitgtk24xHook = set (libraryDepends . pkgconfig . contains (pkg "webkitgtk24x-gtk3")) True
+                 . over (libraryDepends . pkgconfig) (Set.filter (\b -> view localName b /= "webkitgtk24x-gtk3"))
 
 opencvOverrides :: Derivation -> Derivation
 opencvOverrides = set phaseOverrides "hardeningDisable = [ \"bindnow\" ];"
diff --git a/src/Distribution/Nixpkgs/Haskell/OrphanInstances.hs b/src/Distribution/Nixpkgs/Haskell/OrphanInstances.hs
--- a/src/Distribution/Nixpkgs/Haskell/OrphanInstances.hs
+++ b/src/Distribution/Nixpkgs/Haskell/OrphanInstances.hs
@@ -1,7 +1,3 @@
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE DeriveGeneric      #-}
-{-# LANGUAGE StandaloneDeriving #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 
 module Distribution.Nixpkgs.Haskell.OrphanInstances ( ) where
@@ -13,45 +9,47 @@
 import Data.Yaml
 import Distribution.Compiler
 import Distribution.License
-import Distribution.ModuleName hiding ( main, fromString )
 import Distribution.Package
 import Distribution.PackageDescription
 import Distribution.System
 import Distribution.Text
+import Distribution.Types.CondTree
+import Distribution.Types.ExecutableScope
+import Distribution.Types.ForeignLib
+import Distribution.Types.ForeignLibOption
+import Distribution.Types.ForeignLibType
+import Distribution.Types.IncludeRenaming
+import Distribution.Types.Mixin
 import Distribution.Version
 import Language.Haskell.Extension
 
-#if !MIN_VERSION_Cabal(1,23,0)
-import GHC.Generics ( Generic )
-deriving instance Generic (CondTree v c a)
-deriving instance Generic (Condition a)
-deriving instance Generic ConfVar
-deriving instance Generic Flag
-deriving instance Generic GenericPackageDescription
-#else
 instance NFData SetupBuildInfo
-#endif
-
 instance (NFData v, NFData c, NFData a) => NFData (CondTree v c a)
+instance (NFData v, NFData c, NFData a) => NFData (CondBranch v c a)
 instance NFData Arch
 instance NFData Benchmark
 instance NFData BenchmarkInterface
 instance NFData BenchmarkType
 instance NFData BuildInfo
 instance NFData BuildType
+instance NFData LibVersionInfo
 instance NFData CompilerFlavor
 instance NFData ConfVar
-instance NFData Dependency
+instance NFData ExecutableScope
+instance NFData IncludeRenaming
+instance NFData ForeignLibType
+instance NFData ForeignLibOption
 instance NFData Executable
 instance NFData Extension
 instance NFData Flag
+instance NFData Mixin
 instance NFData FlagName
 instance NFData GenericPackageDescription
 instance NFData KnownExtension
 instance NFData Language
 instance NFData Library
+instance NFData ForeignLib
 instance NFData License
-instance NFData ModuleName
 instance NFData ModuleReexport
 instance NFData ModuleRenaming
 instance NFData OS
@@ -62,15 +60,11 @@
 instance NFData TestSuite
 instance NFData TestSuiteInterface
 instance NFData TestType
-instance NFData VersionRange
 instance NFData a => NFData (Condition a)
 instance NFData Platform
 instance NFData CompilerInfo
 instance NFData CompilerId
 instance NFData AbiTag
-
-instance IsString PackageName where
-  fromString = text2isString "PackageName"
 
 instance IsString Version where
   fromString = text2isString "Version"
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
@@ -9,7 +9,6 @@
 import qualified Data.ByteString.Lazy.Char8 as LBS8
 import Data.List ( isSuffixOf, isPrefixOf )
 import Data.Maybe
-import Data.Version
 import Distribution.Hackage.DB.Parsed
 import Distribution.Nixpkgs.Fetch
 import Distribution.Nixpkgs.Hashes
@@ -17,7 +16,7 @@
 import qualified Distribution.Package as Cabal
 import Distribution.PackageDescription
 import qualified Distribution.PackageDescription as Cabal
-import Distribution.Text ( simpleParse )
+import Distribution.Text ( simpleParse, display )
 import OpenSSL.Digest ( digest, digestByName )
 import System.Directory ( doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getHomeDirectory, getDirectoryContents )
 import System.Exit ( exitFailure )
@@ -35,7 +34,6 @@
   (derivSource, pkgDesc) <- fetchOrFromDB optHackageDB source
   flip Package pkgDesc <$> maybe (sourceFromHackage (sourceHash source) (showPackageIdentifier pkgDesc) $ sourceCabalDir source) return derivSource
 
-
 fetchOrFromDB :: Maybe String -> Source -> IO (Maybe DerivationSource, Cabal.GenericPackageDescription)
 fetchOrFromDB optHackageDB src
   | "cabal://" `isPrefixOf` sourceUrl src = fmap ((,) Nothing) . fromDB optHackageDB . drop (length "cabal://") $ sourceUrl src
@@ -54,15 +52,12 @@
     Just r -> return r
     Nothing -> hPutStrLn stderr "*** no such package in the cabal database (did you run cabal update?). " >> exitFailure
  where
+  pkgId :: Cabal.PackageIdentifier
   pkgId = fromMaybe (error ("invalid Haskell package id " ++ show pkg)) (simpleParse pkg)
-  Cabal.PackageName name = Cabal.pkgName pkgId
-  version = Cabal.pkgVersion pkgId
+  name = Cabal.unPackageName (Cabal.packageName pkgId)
 
   lookupVersion :: DB.Map DB.Version Cabal.GenericPackageDescription -> Maybe Cabal.GenericPackageDescription
-  lookupVersion
-    | null (versionBranch version) = fmap snd . listToMaybe . reverse . DB.toAscList
-    | otherwise                    = DB.lookup version
-
+  lookupVersion = fmap snd . listToMaybe . reverse . DB.toAscList
 
 readFileMay :: String -> IO (Maybe String)
 readFileMay file = do
@@ -117,9 +112,9 @@
           exitFailure
 
 showPackageIdentifier :: Cabal.GenericPackageDescription -> String
-showPackageIdentifier pkgDesc = name ++ "-" ++ showVersion version where
+showPackageIdentifier pkgDesc = name ++ "-" ++ display version where
   pkgId = Cabal.package . Cabal.packageDescription $ pkgDesc
-  Cabal.PackageName name = Cabal.packageName pkgId
+  name = Cabal.unPackageName (Cabal.packageName pkgId)
   version = Cabal.packageVersion pkgId
 
 cabalFromPath :: FilePath -> MaybeT IO (Bool, Cabal.GenericPackageDescription)
