diff --git a/cabal2nix.cabal b/cabal2nix.cabal
--- a/cabal2nix.cabal
+++ b/cabal2nix.cabal
@@ -1,5 +1,5 @@
 name:           cabal2nix
-version:        2.8.2
+version:        2.9
 synopsis:       Convert Cabal files into Nix build instructions.
 category:       Distribution, Nix
 stability:      stable
@@ -97,7 +97,7 @@
   other-extensions: CPP DeriveGeneric FlexibleInstances MultiParamTypeClasses OverloadedStrings RecordWildCards ScopedTypeVariables StandaloneDeriving TemplateHaskell
   ghc-options: -Wall
   build-depends:
-      Cabal >2
+      Cabal >2.2
     , aeson
     , ansi-wl-pprint
     , base <5
@@ -107,7 +107,7 @@
     , directory
     , distribution-nixpkgs >=1.1
     , filepath
-    , hackage-db >2
+    , hackage-db >=2.0.1
     , hopenssl >=2
     , hpack >= 0.26
     , language-nix
@@ -153,7 +153,7 @@
   hs-source-dirs: hackage2nix
   ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
   build-depends:
-      Cabal >2
+      Cabal >2.2
     , aeson
     , base <5
     , bytestring
@@ -181,7 +181,7 @@
   main-is:              Main.hs
   hs-source-dirs:       test
   build-depends:        base
-                      , Cabal > 2
+                      , Cabal >2.2
                       , cabal2nix
                       , filepath
                       , language-nix
@@ -189,5 +189,6 @@
                       , pretty
                       , tasty
                       , tasty-golden
-  ghc-options:          -Wall
+                        -- TODO: Why does 1K not work any longer?
+  ghc-options:          -Wall -with-rtsopts=-K48K
   default-language:     Haskell2010
diff --git a/hackage2nix/HackageGit.hs b/hackage2nix/HackageGit.hs
--- a/hackage2nix/HackageGit.hs
+++ b/hackage2nix/HackageGit.hs
@@ -10,17 +10,15 @@
 import Control.Lens hiding ( (<.>) )
 import Control.Monad
 import Data.Aeson
-import Data.ByteString.Char8 ( ByteString )
 import qualified Data.ByteString.Char8 as BS
 import Data.Map as Map
 import Data.Set as Set
 import Data.String
-import Data.String.UTF8 ( toString, fromRep )
 import Distribution.Nixpkgs.Hashes
 import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
 import Distribution.Package
 import Distribution.PackageDescription
-import Distribution.PackageDescription.Parse ( parseGenericPackageDescription, ParseResult(..) )
+import Distribution.PackageDescription.Parsec ( parseGenericPackageDescriptionMaybe )
 import Distribution.Text
 import Distribution.Version
 import OpenSSL.Digest ( digest, digestByName )
@@ -42,18 +40,15 @@
   let isDirectory p = doesDirectoryExist (path </> p)
   getDirectoryContents path >>= filterM isDirectory . Prelude.filter (\x -> head x /= '.')
 
-decodeUTF8 :: ByteString -> String
-decodeUTF8 = toString . fromRep
-
 type SHA256Hash = String
 
 readPackage :: FilePath -> PackageIdentifier -> IO (GenericPackageDescription, SHA256Hash)
 readPackage dirPrefix (PackageIdentifier name version) = do
   let cabalFile = dirPrefix </> unPackageName name </> display version </> unPackageName name <.> "cabal"
   buf <- BS.readFile cabalFile
-  cabal <- case parseGenericPackageDescription (decodeUTF8 buf) of
-             ParseOk _ a  -> return a
-             ParseFailed err -> fail (cabalFile ++ ": " ++ show err)
+  cabal <- case parseGenericPackageDescriptionMaybe buf of
+             Just a  -> return a
+             Nothing -> fail ("cannot parse cabal file " ++ cabalFile)
   return (cabal, printSHA256 (digest (digestByName "sha256") buf))
 
 declareLenses [d|
diff --git a/hackage2nix/Main.hs b/hackage2nix/Main.hs
--- a/hackage2nix/Main.hs
+++ b/hackage2nix/Main.hs
@@ -78,9 +78,7 @@
             . 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 ("wai-middleware-prometheus")) ((fmap (set (contains "0.2.0") False))) -- TODO: https://github.com/commercialhaskell/all-cabal-hashes/issues/15
+            . over (at ("hermes")) ((fmap (set (contains "1.3.4.3") False)))  -- TODO: https://github.com/haskell/hackage-server/issues/436
   hackage <- fixup <$> readHackage hackageRepository
   let
       hackagePackagesFile :: FilePath
diff --git a/src/Cabal2nix.hs b/src/Cabal2nix.hs
--- a/src/Cabal2nix.hs
+++ b/src/Cabal2nix.hs
@@ -19,13 +19,12 @@
 import Distribution.Nixpkgs.Fetch
 import Distribution.Nixpkgs.Haskell
 import Distribution.Nixpkgs.Haskell.FromCabal
-import Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalizeCabalFlags )
 import Distribution.Nixpkgs.Haskell.FromCabal.Flags
 import qualified Distribution.Nixpkgs.Haskell.FromCabal.PostProcess as PP (pkg)
 import qualified Distribution.Nixpkgs.Haskell.Hackage as DB
 import Distribution.Nixpkgs.Haskell.PackageSourceSpec
 import Distribution.Nixpkgs.Meta
-import Distribution.PackageDescription ( mkFlagName, FlagAssignment )
+import Distribution.PackageDescription ( mkFlagName, mkFlagAssignment, FlagAssignment )
 import Distribution.Package ( packageId )
 import Distribution.Simple.Utils ( lowercase )
 import Distribution.System
@@ -164,8 +163,7 @@
       withHpackOverrides = if pkgRanHpack pkg then hpackOverrides else id
 
       flags :: FlagAssignment
-      flags = normalizeCabalFlags $
-                configureCabalFlags (packageId (pkgCabal pkg)) ++ readFlagList optFlags
+      flags = configureCabalFlags (packageId (pkgCabal pkg)) `mappend` readFlagList optFlags
 
       deriv :: Derivation
       deriv = withHpackOverrides $ fromGenericPackageDescription (const True)
@@ -219,6 +217,6 @@
     Right d -> pPrint d
 
 readFlagList :: [String] -> FlagAssignment
-readFlagList = map tagWithValue
+readFlagList = mkFlagAssignment . map tagWithValue
   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
@@ -23,7 +23,7 @@
 import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
 import Distribution.Nixpkgs.Meta
 import Distribution.Package
-import Distribution.PackageDescription ( FlagAssignment, unFlagName )
+import Distribution.PackageDescription ( FlagAssignment, unFlagName, unFlagAssignment )
 import GHC.Generics ( Generic )
 import Language.Nix
 import Language.Nix.PrettyPrinting
@@ -140,7 +140,7 @@
                           , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
                           ]
 
-      renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- _cabalFlags ]
+      renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- unFlagAssignment _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
@@ -11,6 +11,7 @@
 import Data.Set ( Set )
 import qualified Data.Set as Set
 import Distribution.Compiler
+import Distribution.License
 import Distribution.Nixpkgs.Haskell
 import qualified Distribution.Nixpkgs.Haskell as Nix
 import Distribution.Nixpkgs.Haskell.Constraint
@@ -115,7 +116,7 @@
     xrev = maybe 0 read (lookup "x-revision" customFieldsPD)
 
     nixLicense :: Nix.License
-    nixLicense = fromCabalLicense license
+    nixLicense =  fromCabalLicense (either licenseFromSPDX id licenseRaw)
 
     resolveInHackage :: Identifier -> Binding
     resolveInHackage i | (i^.ident) `elem` [ unPackageName n | (Dependency n _) <- missingDeps ] = bindNull i
@@ -141,6 +142,7 @@
     internalLibNames = fmap unqualComponentNameToPackageName . catMaybes $ libName <$> subLibraries
 
     convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
+    convertBuildInfo Cabal.BuildInfo {..} | not buildable = mempty
     convertBuildInfo Cabal.BuildInfo {..} = mempty
       & haskell .~ Set.fromList [ resolveInHackage (toNixName x) | (Dependency x _) <- targetBuildDepends, x `notElem` internalLibNames ]
       & system .~ Set.fromList [ resolveInNixpkgs y | x <- extraLibs, y <- libNixName x ]
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
@@ -9,7 +9,10 @@
 import Distribution.Version
 
 configureCabalFlags :: PackageIdentifier -> FlagAssignment
-configureCabalFlags (PackageIdentifier name version)
+configureCabalFlags = mkFlagAssignment . configureCabalFlags'
+
+configureCabalFlags' :: PackageIdentifier -> [(FlagName,Bool)]
+configureCabalFlags' (PackageIdentifier name version)
  | name == "accelerate-examples"= [disable "opencl"]
  | name == "arithmoi"           = [disable "llvm"]
  | name == "cabal-plan"         = [enable "exe"]
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
@@ -48,13 +48,13 @@
 libNixName "gdk-pixbuf-2.0"                     = return "gdk_pixbuf"
 libNixName "gdk-x11-2.0"                        = return "gdk_x11"
 libNixName "gio-2.0"                            = return "glib"
-libNixName "GL"                                 = return "mesa"
-libNixName "GLU"                                = ["freeglut","mesa"]
-libNixName "glut"                               = ["freeglut","mesa"]
-libNixName "gnome-keyring"                      = return "gnome_keyring"
-libNixName "gnome-keyring-1"                    = return "gnome_keyring"
-libNixName "gnome-vfs-2.0"                      = return "gnome_vfs"
-libNixName "gnome-vfs-module-2.0"               = return "gnome_vfs_module"
+libNixName "GL"                                 = return "libGL"
+libNixName "GLU"                                = ["libGLU","libGL"]
+libNixName "glut"                               = ["freeglut","libGLU","libGL"]
+libNixName "gnome-keyring"                      = return "gnome-keyring"
+libNixName "gnome-keyring-1"                    = return "gnome-keyring"
+libNixName "gnome-vfs-2.0"                      = return "gnome-vfs"
+libNixName "gnome-vfs-module-2.0"               = return "gnome-vfs_module"
 libNixName "gobject-2.0"                        = return "glib"
 libNixName "gobject-introspection-1.0"          = return "gobjectIntrospection"
 libNixName "gstreamer-audio-0.10"               = return "gst-plugins-base"
@@ -145,7 +145,7 @@
 libNixName "uuid"                               = return "libossp_uuid";
 libNixName "wayland-client"                     = return "wayland"
 libNixName "wayland-cursor"                     = return "wayland"
-libNixName "wayland-egl"                        = return "mesa"
+libNixName "wayland-egl"                        = return "libGL"
 libNixName "wayland-server"                     = return "wayland"
 libNixName "webkit2gtk-4.0"                     = return "webkitgtk"    -- This is the current API, so let it reference an alias for the latest version.
 libNixName "webkit2gtk-web-extension-4.0"       = return "webkitgtk-web-extension"  -- This package doesn't actually exist in nixpkgs at present.
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,17 +1,13 @@
 {-# LANGUAGE OverloadedStrings #-}
 
-module Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalize, normalizeCabalFlags ) where
+module Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalize ) where
 
 import Control.Lens
-import Data.Function
-import Data.List
 import qualified Data.Set as Set
 import Data.String
 import Distribution.Nixpkgs.Haskell
 import Distribution.Nixpkgs.Meta
 import Distribution.Package
-import Distribution.PackageDescription ( FlagAssignment, mkFlagName, unFlagName )
-import Distribution.Simple.Utils ( lowercase )
 import Language.Nix hiding ( quote )
 
 normalize :: Derivation -> Derivation
@@ -21,7 +17,6 @@
   & over testDepends (normalizeBuildInfo (packageName drv))
   & over benchmarkDepends (normalizeBuildInfo (packageName drv))
   & over metaSection normalizeMeta
-  & over cabalFlags normalizeCabalFlags
   & jailbreak %~ (&& (packageName drv /= "jailbreak-cabal"))
 
 normalizeBuildInfo :: PackageName -> BuildInfo -> BuildInfo
@@ -46,17 +41,3 @@
 quote ('"':cs)    = '\\' : '"' : quote cs
 quote (c:cs)      = c : quote cs
 quote []          = []
-
--- | When a flag is specified multiple times, the last occurrence counts. Flag
--- names are spelled all lowercase.
---
--- >>> normalizeCabalFlags [(mkFlagName "foo", True), (mkFlagName "FOO", True), (mkFlagName "Foo", False)]
--- [(FlagName "foo",False)]
-
-normalizeCabalFlags :: FlagAssignment -> FlagAssignment
-normalizeCabalFlags flags =
-  sortBy (compare `on` fst) $
-    reverse $
-      nubBy ((==) `on` fst) $
-        reverse
-          [ (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
@@ -42,9 +42,9 @@
   , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList [bind "pkgs.xorg.libXext", bind "pkgs.xorg.libXfixes"])))
   , ("bindings-lxc", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux)))                                                                                                      , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
   , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
+  , ("Cabal", set doCheck False) -- test suite doesn't work in Nix
   , ("cabal-helper", set doCheck False) -- https://github.com/DanielG/cabal-helper/issues/17
   , ("cabal-install", set doCheck False . set phaseOverrides cabalInstallPostInstall)
-  , ("Cabal", set doCheck False) -- test suite doesn't work in Nix
   , ("darcs", set phaseOverrides darcsInstallPostInstall . set doCheck False)
   , ("dbus", set doCheck False) -- don't execute tests that try to access the network
   , ("dns", set testTarget "spec")      -- don't execute tests that try to access the network
@@ -52,25 +52,25 @@
   , ("freenect < 1.2.1", over configureFlags (Set.union (Set.fromList ["--extra-include-dirs=${pkgs.freenect}/include/libfreenect", "--extra-lib-dirs=${pkgs.freenect}/lib"])))
   , ("gf", set phaseOverrides gfPhaseOverrides . set doCheck False)
   , ("gi-cairo", giCairoPhaseOverrides)                     -- https://github.com/haskell-gi/haskell-gi/issues/36
+  , ("gi-gst", giGstLibOverrides "gstreamer")               -- https://github.com/haskell-gi/haskell-gi/issues/36
   , ("gi-gstaudio", giGstLibOverrides "gst-plugins-base")   -- https://github.com/haskell-gi/haskell-gi/issues/36
   , ("gi-gstbase", giGstLibOverrides "gst-plugins-base")    -- https://github.com/haskell-gi/haskell-gi/issues/36
-  , ("gi-gst", giGstLibOverrides "gstreamer")               -- https://github.com/haskell-gi/haskell-gi/issues/36
   , ("gi-gstvideo", giGstLibOverrides "gst-plugins-base")   -- https://github.com/haskell-gi/haskell-gi/issues/36
   , ("gi-javascriptcore < 4.0.0.0", webkitgtk24xHook)       -- https://github.com/haskell-gi/haskell-gi/issues/36
-  , ("gio", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
-  , ("gi-pangocairo", giCairoPhaseOverrides)                     -- https://github.com/haskell-gi/haskell-gi/issues/36
   , ("gi-pango", giCairoPhaseOverrides)                     -- https://github.com/haskell-gi/haskell-gi/issues/36
-  , ("git-annex", gitAnnexHook)
+  , ("gi-pangocairo", giCairoPhaseOverrides)                     -- https://github.com/haskell-gi/haskell-gi/issues/36
+  , ("gi-webkit", webkitgtk24xHook)   -- https://github.com/haskell-gi/haskell-gi/issues/36
+  , ("gio", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
+  , ("git", set doCheck False)          -- https://github.com/vincenthz/hit/issues/33
   , ("git-annex >= 6.20170925 && < 6.20171214", set doCheck False)      -- some versions of git-annex require their test suite to be run inside of a git checkout
+  , ("git-annex", gitAnnexHook)
   , ("github-backup", set (executableDepends . tool . contains (pkg "git")) True)
-  , ("git", set doCheck False)          -- https://github.com/vincenthz/hit/issues/33
-  , ("gi-webkit", webkitgtk24xHook)   -- https://github.com/haskell-gi/haskell-gi/issues/36
+  , ("GLFW", over (libraryDepends . system) (Set.union (Set.fromList [bind "pkgs.xorg.libXext", bind "pkgs.xorg.libXfixes"])))
   , ("GlomeVec", set (libraryDepends . pkgconfig . contains (bind "self.llvmPackages.llvm")) True)
   , ("gtk3", gtk3Hook)
   , ("haddock", haddockHook) -- https://github.com/haskell/haddock/issues/511
   , ("hakyll", set (testDepends . tool . contains (pkg "utillinux")) True) -- test suite depends on "rev"
   , ("haskell-src-exts", set doCheck False)
-  , ("hspec-core >= 2.4.4", hspecCoreOverrides)
   , ("hfsevents", hfseventsOverrides)
   , ("HFuse", set phaseOverrides hfusePreConfigure)
   , ("hlibgit2 >= 0.18.0.14", set (testDepends . tool . contains (pkg "git")) True)
@@ -80,8 +80,9 @@
   , ("hsignal < 0.2.7.4", set phaseOverrides "prePatch = \"rm -v Setup.lhs\";") -- https://github.com/amcphail/hsignal/issues/1
   , ("hslua < 0.9.3", over (libraryDepends . each) (replace (pkg "lua") (pkg "lua5_1")))
   , ("hslua >= 0.9.3", over (libraryDepends . each) (replace (pkg "lua") (pkg "lua5_3")))
-  , ("http-client-openssl >= 0.2.0.1", set doCheck False) -- attempts to access the network
+  , ("hspec-core >= 2.4.4", hspecCoreOverrides)
   , ("http-client", set doCheck False)          -- attempts to access the network
+  , ("http-client-openssl >= 0.2.0.1", set doCheck False) -- attempts to access the network
   , ("http-client-tls >= 0.2.2", set doCheck False) -- attempts to access the network
   , ("http-conduit", set doCheck False)         -- attempts to access the network
   , ("imagemagick", set (libraryDepends . pkgconfig . contains (pkg "imagemagick")) True) -- https://github.com/NixOS/cabal2nix/issues/136
@@ -99,8 +100,8 @@
   , ("numeric-qq", set doCheck False) -- test suite doesn't finish even after 1+ days
   , ("opencv", opencvOverrides)
   , ("pandoc >= 1.16.0.2", set doCheck False) -- https://github.com/jgm/pandoc/issues/2709 and https://github.com/fpco/stackage/issues/1332
-  , ("pandoc-citeproc", set doCheck False) -- https://github.com/jgm/pandoc-citeproc/issues/172
   , ("pandoc", set jailbreak False) -- jailbreak-cabal break the build
+  , ("pandoc-citeproc", set doCheck False) -- https://github.com/jgm/pandoc-citeproc/issues/172
   , ("purescript", set doCheck False) -- test suite doesn't cope with Nix build env
   , ("qtah-cpp-qt5", set (libraryDepends . system . contains (bind "pkgs.qt5.qtbase")) True)
   , ("qtah-qt5", set (libraryDepends . tool . contains (bind "pkgs.qt5.qtbase")) True)
@@ -119,13 +120,13 @@
   , ("twilio", set doCheck False)         -- attempts to access the network
   , ("tz", set phaseOverrides "preConfigure = \"export TZDIR=${pkgs.tzdata}/share/zoneinfo\";")
   , ("udev", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux)))                                                                                                      , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
-  , ("webkitgtk3-javascriptcore", webkitgtk24xHook)   -- https://github.com/haskell-gi/haskell-gi/issues/36
   , ("webkitgtk3", webkitgtk24xHook)   -- https://github.com/haskell-gi/haskell-gi/issues/36
+  , ("webkitgtk3-javascriptcore", webkitgtk24xHook)   -- https://github.com/haskell-gi/haskell-gi/issues/36
   , ("websockets", set doCheck False)   -- https://github.com/jaspervdj/websockets/issues/104
   , ("Win32", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Windows)))
   , ("Win32-shortcut", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Windows)))
-  , ("wxcore", set (libraryDepends . pkgconfig . contains (pkg "wxGTK")) True)
   , ("wxc", wxcHook)
+  , ("wxcore", set (libraryDepends . pkgconfig . contains (pkg "wxGTK")) True)
   , ("X11", over (libraryDepends . system) (Set.union (Set.fromList $ map bind ["pkgs.xorg.libXinerama","pkgs.xorg.libXext","pkgs.xorg.libXrender","pkgs.xorg.libXScrnSaver"])))
   , ("xmonad", set phaseOverrides xmonadPostInstall)
   , ("zip-archive < 0.3.1", over (testDepends . tool) (replace (bind "self.zip") (pkg "zip")))
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
@@ -1,7 +1,8 @@
 module Distribution.Nixpkgs.Haskell.Hackage
   ( HackageDB, PackageData, VersionData(..)
   , hackageTarball, readTarball
-  ) where
+  )
+  where
 
 import Data.Map as Map
 import qualified Distribution.Hackage.DB.Parsed as P
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
@@ -8,62 +8,12 @@
 import qualified Data.Text as T
 import Data.Yaml
 import Distribution.Compiler
-import Distribution.License
 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
 
-instance NFData SetupBuildInfo
-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 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 ModuleReexport
-instance NFData ModuleRenaming
-instance NFData OS
-instance NFData PackageDescription
-instance NFData RepoKind
-instance NFData RepoType
-instance NFData SourceRepo
-instance NFData TestSuite
-instance NFData TestSuiteInterface
-instance NFData TestType
-instance NFData a => NFData (Condition a)
-instance NFData Platform
 instance NFData CompilerInfo
-instance NFData CompilerId
 instance NFData AbiTag
 
 instance IsString Version where
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
@@ -2,10 +2,12 @@
   ( Package(..), getPackage, getPackage', loadHackageDB, sourceFromHackage
   ) where
 
+import Control.DeepSeq (force)
 import qualified Control.Exception as Exception
 import Control.Monad
 import Control.Monad.IO.Class
 import Control.Monad.Trans.Maybe
+import qualified Data.ByteString.Char8 as BS -- TODO: Deal with utf-8 encoding!!
 import Data.List ( isSuffixOf, isPrefixOf )
 import qualified Data.Map as DB
 import Data.Maybe
@@ -16,16 +18,16 @@
 import qualified Distribution.Package as Cabal
 import Distribution.PackageDescription
 import qualified Distribution.PackageDescription as Cabal
-import Distribution.PackageDescription.Parse as Cabal
+import Distribution.PackageDescription.Parsec as Cabal
 import Distribution.Text ( simpleParse, display )
 import Distribution.Version
-import qualified Hpack.Render as Hpack
 import qualified Hpack.Config as Hpack
+import qualified Hpack.Render as Hpack
 import OpenSSL.Digest ( digestString, digestByName )
 import System.Directory ( doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getHomeDirectory, getDirectoryContents )
 import System.Exit ( exitFailure )
 import System.FilePath ( (</>), (<.>) )
-import System.IO ( hPutStrLn, stderr, hPutStr )
+import System.IO
 
 data Package = Package
   { pkgSource   :: DerivationSource
@@ -197,27 +199,26 @@
     Right (Hpack.DecodeResult pkg' _ _) -> do
       let hpackOutput = Hpack.renderPackage [] pkg'
           hash = printSHA256 $ digestString (digestByName "sha256") hpackOutput
-      case parseGenericPackageDescription hpackOutput of
-        ParseFailed perr -> liftIO $ do
-          hPutStrLn stderr $ "*** cannot parse hpack output: " ++ show perr
-          hPutStrLn stderr $ "*** hpack output:\n" ++ hpackOutput
+      case parseGenericPackageDescriptionMaybe (BS.pack hpackOutput) of
+        Nothing -> liftIO $ do
+          hPutStrLn stderr "*** cannot parse hpack output:"
+          hPutStrLn stderr hpackOutput
           fail "*** Exiting."
-        ParseOk _ pkg -> MaybeT $ return $ Just $ (,) True $ setCabalFileHash hash pkg
+        Just pkg -> MaybeT $ return $ Just $ (,) True $ setCabalFileHash hash pkg
 
 cabalFromFile :: Bool -> FilePath -> MaybeT IO Cabal.GenericPackageDescription
 cabalFromFile failHard file =
-  -- readFile throws an error if it's used on binary files which contain sequences
+  -- hGetContents throws an error if it's used on files which contain sequences
   -- that do not represent valid characters. To catch that exception, we need to
-  -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
-  -- the reading of the file, so we will always catch the expression here.
+  -- wrap the whole block in `catchIO`.
   MaybeT $ handleIO (\err -> Nothing <$ hPutStrLn stderr ("*** parsing cabal file: " ++ show err)) $ do
-    buf <- readFile file
+    buf <- withFile file ReadMode $ \ h -> do
+      hSetEncoding h utf8
+      hGetContents h >>= Exception.evaluate . force
     let hash = printSHA256 (digestString (digestByName "sha256") buf)
-    case parseGenericPackageDescription buf of
-      ParseFailed perr -> if failHard
-                             then fail ("cannot parse " ++ show file ++ ": " ++ show perr)
-                             else return Nothing
-      ParseOk _ pkg    -> return $ Just $ setCabalFileHash hash pkg
+    case parseGenericPackageDescriptionMaybe (BS.pack buf) of
+      Nothing  -> if failHard then fail ("cannot parse " ++ show file) else return Nothing
+      Just pkg -> return $ Just $ setCabalFileHash hash pkg
 
 setCabalFileHash :: String -> GenericPackageDescription -> GenericPackageDescription
 setCabalFileHash sha256 gpd = gpd { packageDescription = (packageDescription gpd) {
diff --git a/test/Main.hs b/test/Main.hs
--- a/test/Main.hs
+++ b/test/Main.hs
@@ -7,7 +7,7 @@
 import Control.Lens
 import Distribution.Compiler
 import Distribution.PackageDescription
-import Distribution.PackageDescription.Parse
+import Distribution.PackageDescription.Parsec
 import Distribution.System
 import Distribution.Verbosity
 import Distribution.Version
@@ -19,6 +19,8 @@
 
 main :: IO ()
 main = do
+  -- TODO: run this test with all kinds of setLocaleEncoding values to ensure we don't
+  -- depend on the system environment: https://github.com/NixOS/cabal2nix/issues/333
   testCases <- findByExtension [".cabal"] "test/golden-test-cases"
   defaultMain $ testGroup "regression-tests" (map regressionTest testCases)
 
@@ -33,7 +35,7 @@
                         (\i -> Just (binding # (i, path # [i])))
                         (Platform X86_64 Linux)
                         (unknownCompilerInfo (CompilerId GHC (mkVersion [8,2])) NoAbiTag)
-                        []
+                        mempty
                         []
                         gpd
                       & src .~ DerivationSource
diff --git a/test/golden-test-cases/SHA.nix.golden b/test/golden-test-cases/SHA.nix.golden
--- a/test/golden-test-cases/SHA.nix.golden
+++ b/test/golden-test-cases/SHA.nix.golden
@@ -1,5 +1,5 @@
-{ mkDerivation, array, base, binary, bytestring, directory
-, fetchurl, QuickCheck, test-framework, test-framework-quickcheck2
+{ mkDerivation, array, base, binary, bytestring, fetchurl
+, QuickCheck, test-framework, test-framework-quickcheck2
 }:
 mkDerivation {
   pname = "SHA";
@@ -11,7 +11,6 @@
   isLibrary = true;
   isExecutable = true;
   libraryHaskellDepends = [ array base binary bytestring ];
-  executableHaskellDepends = [ base bytestring directory ];
   testHaskellDepends = [
     array base binary bytestring QuickCheck test-framework
     test-framework-quickcheck2
diff --git a/test/golden-test-cases/butcher.nix.golden b/test/golden-test-cases/butcher.nix.golden
--- a/test/golden-test-cases/butcher.nix.golden
+++ b/test/golden-test-cases/butcher.nix.golden
@@ -13,10 +13,6 @@
     base bifunctors containers deque either extra free microlens
     microlens-th mtl multistate pretty transformers unsafe void
   ];
-  testHaskellDepends = [
-    base containers deque either extra free microlens microlens-th mtl
-    multistate pretty transformers unsafe
-  ];
   homepage = "https://github.com/lspitzner/butcher/";
   description = "Chops a command or program invocation into digestable pieces";
   license = stdenv.lib.licenses.bsd3;
diff --git a/test/golden-test-cases/giphy-api.nix.golden b/test/golden-test-cases/giphy-api.nix.golden
--- a/test/golden-test-cases/giphy-api.nix.golden
+++ b/test/golden-test-cases/giphy-api.nix.golden
@@ -17,7 +17,6 @@
     microlens microlens-th mtl network-uri servant servant-client text
     transformers
   ];
-  executableHaskellDepends = [ base network-uri text ];
   testHaskellDepends = [
     aeson base basic-prelude bytestring containers directory hspec lens
     network-uri text
diff --git a/test/golden-test-cases/gl.nix.golden b/test/golden-test-cases/gl.nix.golden
--- a/test/golden-test-cases/gl.nix.golden
+++ b/test/golden-test-cases/gl.nix.golden
@@ -1,5 +1,5 @@
 { mkDerivation, base, Cabal, containers, directory, fetchurl
-, filepath, fixed, half, hxt, mesa, transformers
+, filepath, fixed, half, hxt, libGL, transformers
 }:
 mkDerivation {
   pname = "gl";
@@ -14,7 +14,7 @@
   libraryHaskellDepends = [
     base containers fixed half transformers
   ];
-  librarySystemDepends = [ mesa ];
+  librarySystemDepends = [ libGL ];
   description = "Complete OpenGL raw bindings";
   license = stdenv.lib.licenses.bsd3;
 }
diff --git a/test/golden-test-cases/highlighting-kate.nix.golden b/test/golden-test-cases/highlighting-kate.nix.golden
--- a/test/golden-test-cases/highlighting-kate.nix.golden
+++ b/test/golden-test-cases/highlighting-kate.nix.golden
@@ -15,7 +15,6 @@
     base blaze-html containers mtl parsec regex-pcre-builtin
     utf8-string
   ];
-  executableHaskellDepends = [ base blaze-html containers filepath ];
   testHaskellDepends = [
     base blaze-html containers Diff directory filepath process
   ];
diff --git a/test/golden-test-cases/mwc-random.nix.golden b/test/golden-test-cases/mwc-random.nix.golden
--- a/test/golden-test-cases/mwc-random.nix.golden
+++ b/test/golden-test-cases/mwc-random.nix.golden
@@ -1,6 +1,5 @@
-{ mkDerivation, base, fetchurl, HUnit, math-functions, primitive
-, QuickCheck, statistics, test-framework, test-framework-hunit
-, test-framework-quickcheck2, time, vector
+{ mkDerivation, base, fetchurl, math-functions, primitive, time
+, vector
 }:
 mkDerivation {
   pname = "mwc-random";
@@ -11,10 +10,6 @@
   };
   libraryHaskellDepends = [
     base math-functions primitive time vector
-  ];
-  testHaskellDepends = [
-    base HUnit QuickCheck statistics test-framework
-    test-framework-hunit test-framework-quickcheck2 vector
   ];
   doCheck = false;
   homepage = "https://github.com/bos/mwc-random";
diff --git a/test/golden-test-cases/servant-checked-exceptions.nix.golden b/test/golden-test-cases/servant-checked-exceptions.nix.golden
--- a/test/golden-test-cases/servant-checked-exceptions.nix.golden
+++ b/test/golden-test-cases/servant-checked-exceptions.nix.golden
@@ -1,8 +1,7 @@
 { mkDerivation, aeson, base, bytestring, deepseq, doctest, fetchurl
-, Glob, hspec-wai, http-api-data, http-client, http-media
-, natural-transformation, optparse-applicative, profunctors
-, servant, servant-client, servant-docs, servant-server, tagged
-, tasty, tasty-hspec, tasty-hunit, text, wai, warp
+, Glob, hspec-wai, http-media, profunctors, servant, servant-client
+, servant-docs, servant-server, tagged, tasty, tasty-hspec
+, tasty-hunit, text, wai
 }:
 mkDerivation {
   pname = "servant-checked-exceptions";
@@ -16,11 +15,6 @@
   libraryHaskellDepends = [
     aeson base bytestring deepseq http-media profunctors servant
     servant-client servant-docs servant-server tagged text
-  ];
-  executableHaskellDepends = [
-    aeson base http-api-data http-client natural-transformation
-    optparse-applicative servant servant-client servant-docs
-    servant-server text wai warp
   ];
   testHaskellDepends = [
     base bytestring doctest Glob hspec-wai servant servant-server tasty
diff --git a/test/golden-test-cases/texmath.nix.golden b/test/golden-test-cases/texmath.nix.golden
--- a/test/golden-test-cases/texmath.nix.golden
+++ b/test/golden-test-cases/texmath.nix.golden
@@ -1,6 +1,6 @@
 { mkDerivation, base, bytestring, containers, directory, fetchurl
-, filepath, mtl, network-uri, pandoc-types, parsec, process, split
-, syb, temporary, text, utf8-string, xml
+, filepath, mtl, pandoc-types, parsec, process, split, syb
+, temporary, text, utf8-string, xml
 }:
 mkDerivation {
   pname = "texmath";
@@ -14,7 +14,6 @@
   libraryHaskellDepends = [
     base containers mtl pandoc-types parsec syb xml
   ];
-  executableHaskellDepends = [ network-uri ];
   testHaskellDepends = [
     base bytestring directory filepath process split temporary text
     utf8-string xml
diff --git a/test/golden-test-cases/weigh.nix.golden b/test/golden-test-cases/weigh.nix.golden
--- a/test/golden-test-cases/weigh.nix.golden
+++ b/test/golden-test-cases/weigh.nix.golden
@@ -1,6 +1,5 @@
-{ mkDerivation, base, bytestring-trie, containers, deepseq
-, fetchurl, mtl, process, random, split, template-haskell
-, temporary, unordered-containers
+{ mkDerivation, base, deepseq, fetchurl, mtl, process, split
+, template-haskell, temporary
 }:
 mkDerivation {
   pname = "weigh";
@@ -12,9 +11,7 @@
   libraryHaskellDepends = [
     base deepseq mtl process split template-haskell temporary
   ];
-  testHaskellDepends = [
-    base bytestring-trie containers deepseq random unordered-containers
-  ];
+  testHaskellDepends = [ base deepseq ];
   homepage = "https://github.com/fpco/weigh#readme";
   description = "Measure allocations of a Haskell functions/values";
   license = stdenv.lib.licenses.bsd3;
