diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,6 +1,15 @@
-module Main (main) where
+module Main ( main ) where
 
 import Distribution.Simple
+import Distribution.Simple.LocalBuildInfo ( withPrograms )
+import Distribution.Simple.Program ( userSpecifyArgs )
 
 main :: IO ()
-main = defaultMain
+main = defaultMainWithHooks $
+         simpleUserHooks `modify_haddockHook` \oldHH pkg lbi hooks flags ->
+           (\lbi' -> oldHH pkg lbi' hooks flags) $
+             lbi `modify_withPrograms` \oldWP ->
+               userSpecifyArgs "haddock" ["--optghc=-D__HADDOCK__"] oldWP
+  where
+    modify_haddockHook  hooks f = hooks { haddockHook  = f (haddockHook  hooks) }
+    modify_withPrograms lbi   f = lbi   { withPrograms = f (withPrograms lbi)   }
diff --git a/cabal2nix.cabal b/cabal2nix.cabal
--- a/cabal2nix.cabal
+++ b/cabal2nix.cabal
@@ -1,5 +1,5 @@
 Name:                   cabal2nix
-Version:                1.25
+Version:                1.26
 Copyright:              Peter Simons, Andres Loeh
 License:                BSD3
 License-File:           LICENSE
@@ -9,7 +9,7 @@
 Category:               Distribution
 Synopsis:               Convert Cabal files into Nix build instructions
 Cabal-Version:          >= 1.8
-Build-Type:             Simple
+Build-Type:             Custom
 Tested-With:            GHC == 6.12.3, GHC == 7.0.4, GHC == 7.4.1
 Data-files:             README.md
 Description:
@@ -31,8 +31,8 @@
   .
   The only required argument is the path to the cabal file. For example:
   .
-  > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.25/cabal2nix.cabal
-  > cabal2nix cabal://cabal2nix-1.25
+  > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.26/cabal2nix.cabal
+  > cabal2nix cabal://cabal2nix-1.26
   .
   If the @--sha256@ option has not been specified, cabal2nix calls
   @nix-prefetch-url@ to determine the hash automatically. This causes
@@ -46,7 +46,7 @@
   main-is:              Cabal2Nix.hs
   hs-source-dirs:       src
   Build-Depends:        base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,
-                        filepath, directory, process, HTTP, nixos-types >= 1.2
+                        filepath, directory, process, HTTP
   Extensions:           PatternGuards, RecordWildCards, CPP
   Ghc-Options:          -Wall
   other-modules:        Cabal2Nix.CorePackages
@@ -57,13 +57,16 @@
                         Cabal2Nix.Name
                         Cabal2Nix.Normalize
                         Cabal2Nix.PostProcess
+                        Distribution.NixOS.Derivation.Cabal
+                        Distribution.NixOS.Derivation.License
+                        Distribution.NixOS.Derivation.Meta
+                        Distribution.NixOS.PrettyPrinting
 
 Executable hackage4nix
   main-is:              Hackage4Nix.hs
   hs-source-dirs:       src
   Build-Depends:        base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,
-                        mtl, containers, directory, filepath, nixos-types >= 1.2,
-                        hackage-db
+                        mtl, containers, directory, filepath, hackage-db
   Extensions:           PatternGuards, RecordWildCards, CPP
   Ghc-Options:          -Wall
   other-modules:        Cabal2Nix.CorePackages
@@ -73,3 +76,7 @@
                         Cabal2Nix.Name
                         Cabal2Nix.Normalize
                         Cabal2Nix.PostProcess
+                        Distribution.NixOS.Derivation.Cabal
+                        Distribution.NixOS.Derivation.License
+                        Distribution.NixOS.Derivation.Meta
+                        Distribution.NixOS.PrettyPrinting
diff --git a/src/Cabal2Nix/CorePackages.hs b/src/Cabal2Nix/CorePackages.hs
--- a/src/Cabal2Nix/CorePackages.hs
+++ b/src/Cabal2Nix/CorePackages.hs
@@ -13,12 +13,12 @@
     "base",
     "bin-package-db",
     "bytestring",
-    "Cabal",
+    -- "Cabal",
     "containers",
     "directory",
     -- "extensible-exceptions",
     "ffi",
-    "filepath",
+    -- "filepath",
     "ghc",
     "ghc-binary",
     "ghc-prim",
diff --git a/src/Cabal2Nix/Normalize.hs b/src/Cabal2Nix/Normalize.hs
--- a/src/Cabal2Nix/Normalize.hs
+++ b/src/Cabal2Nix/Normalize.hs
@@ -10,7 +10,7 @@
 
 normalize :: Derivation -> Derivation
 normalize deriv@(MkDerivation {..}) = deriv
-  { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) $ buildDepends)
+  { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) $ ("Cabal" : buildDepends))
   , buildTools   = normalizeNixBuildTools (filter (`notElem` coreBuildTools) $ buildTools)
   , extraLibs    = normalizeNixLibs extraLibs
   , pkgConfDeps  = normalizeNixLibs pkgConfDeps
diff --git a/src/Distribution/NixOS/Derivation/Cabal.hs b/src/Distribution/NixOS/Derivation/Cabal.hs
new file mode 100644
--- /dev/null
+++ b/src/Distribution/NixOS/Derivation/Cabal.hs
@@ -0,0 +1,134 @@
+{-# LANGUAGE PatternGuards, CPP #-}
+{- |
+   Module      :  Distribution.NixOS.Derivation.Cabal
+   License     :  BSD3
+
+   Maintainer  :  nix-dev@cs.uu.nl
+   Stability   :  provisional
+   Portability :  PatternGuards
+
+   A represtation of Nix expressions based on Cabal builder defined in
+   @pkgs\/development\/libraries\/haskell\/cabal\/cabal.nix@.
+-}
+
+module Distribution.NixOS.Derivation.Cabal
+  ( Derivation(..)
+  , parseDerivation
+  , module Distribution.NixOS.Derivation.Meta
+  , module Data.Version
+  )
+  where
+
+import Distribution.NixOS.Derivation.Meta
+import Distribution.NixOS.PrettyPrinting
+import Distribution.Text
+import Distribution.Package
+#ifdef __HADDOCK__
+import Distribution.PackageDescription ( PackageDescription )
+#endif
+import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
+import Data.Version
+import Data.List
+import Data.Char
+import Text.Regex.Posix hiding ( empty )
+
+-- | A represtation of Nix expressions for building Haskell packages.
+-- The data type correspond closely to the definition of
+-- 'PackageDescription' from Cabal.
+--
+-- Note that the "Text" instance definition provides pretty-printing,
+-- but no parsing as of now!
+
+data Derivation = MkDerivation
+  { pname               :: String
+  , version             :: Version
+  , sha256              :: String
+  , isLibrary           :: Bool
+  , isExecutable        :: Bool
+  , buildDepends        :: [String]
+  , buildTools          :: [String]
+  , extraLibs           :: [String]
+  , pkgConfDeps         :: [String]
+  , configureFlags      :: [String]
+  , cabalFlags          :: FlagAssignment
+  , runHaddock          :: Bool
+  , metaSection         :: Meta
+  }
+  deriving (Show, Eq, Ord)
+
+instance Text Derivation where
+  disp  = renderDerivation
+  parse = error "parsing Distribution.NixOS.Derivation.Cabal.Derivation is not supported yet"
+
+instance Package Derivation where
+  packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
+
+renderDerivation :: Derivation -> Doc
+renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
+  [ text ""
+  , text "cabal.mkDerivation" <+> lparen <> text "self" <> colon <+> lbrace
+  , nest 2 $ vcat
+    [ attr "pname"   $ string (pname deriv)
+    , attr "version" $ doubleQuotes (disp (version deriv))
+    , attr "sha256"  $ string (sha256 deriv)
+    , boolattr "isLibrary" (not (isLibrary deriv) || (isExecutable deriv)) (isLibrary deriv)
+    , boolattr "isExecutable" (not (isLibrary deriv) || (isExecutable deriv)) (isExecutable deriv)
+    , listattr "buildDepends" (buildDepends deriv)
+    , listattr "buildTools" (buildTools deriv)
+    , listattr "extraLibraries" (extraLibs deriv)
+    , listattr "pkgconfigDepends" (pkgConfDeps deriv)
+    , onlyIf renderedFlags $ attr "configureFlags" $ doubleQuotes (sep renderedFlags)
+    , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv))
+    , disp (metaSection deriv)
+    ]
+  , rbrace <> rparen
+  , text ""
+  ]
+  where
+    inputs = nub $ sortBy (\x y -> compare (map toLower x) (map toLower y)) $ filter (/="cabal") $
+              buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
+    renderedFlags =  [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
+                  ++ map text (configureFlags deriv)
+
+-- | A very incomplete parser that extracts 'pname', 'version',
+-- 'sha256', 'platforms', 'maintainers', and 'runHaddock' from the given
+-- Nix expression.
+
+parseDerivation :: String -> Maybe Derivation
+parseDerivation buf
+  | buf =~ "cabal.mkDerivation"
+  , [name]    <- buf `regsubmatch` "pname *= *\"([^\"]+)\""
+  , [vers']   <- buf `regsubmatch` "version *= *\"([^\"]+)\""
+  , Just vers <- simpleParse vers'
+  , [sha]     <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
+  , plats     <- buf `regsubmatch` "platforms *= *([^;]+);"
+  , maint     <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
+  , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
+              = Just $ MkDerivation
+                  { pname          = name
+                  , version        = vers
+                  , sha256         = sha
+                  , isLibrary      = False
+                  , isExecutable   = False
+                  , buildDepends   = []
+                  , buildTools     = []
+                  , extraLibs      = []
+                  , pkgConfDeps    = []
+                  , configureFlags = []
+                  , cabalFlags     = []
+                  , runHaddock     = case noHaddock of "true":[] -> False
+                                                       _         -> True
+                  , metaSection  = Meta
+                                   { homepage    = ""
+                                   , description = ""
+                                   , license     = Unknown Nothing
+                                   , maintainers = concatMap words maint
+                                   , platforms   = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)
+                                   }
+                  }
+  | otherwise = Nothing
+
+regsubmatch :: String -> String -> [String]
+regsubmatch buf patt = let (_,_,_,x) = f in x
+  where f :: (String,String,String,[String])
+        f = match (makeRegexOpts compExtended execBlank patt) buf
diff --git a/src/Distribution/NixOS/Derivation/License.hs b/src/Distribution/NixOS/Derivation/License.hs
new file mode 100644
--- /dev/null
+++ b/src/Distribution/NixOS/Derivation/License.hs
@@ -0,0 +1,51 @@
+{- |
+   Module      :  Distribution.NixOS.Derivation.License
+   License     :  BSD3
+
+   Maintainer  :  nix-dev@cs.uu.nl
+   Stability   :  provisional
+   Portability :  portable
+
+   Known licenses in Nix expressions are represented using the
+   attributes defined in @pkgs\/lib\/licenses.nix@, and unknown licenses
+   are represented as a literal string.
+ -}
+
+module Distribution.NixOS.Derivation.License ( License(..) ) where
+
+import Distribution.NixOS.PrettyPrinting
+import Distribution.Text
+
+-- | The representation for licenses used in Nix derivations. Known
+-- licenses are Nix expressions -- such as @stdenv.lib.licenses.bsd3@
+-- --, so their exact \"name\" is not generally known, because the path
+-- to @stdenv@ depends on the context defined in the expression. In
+-- Cabal expressions, for example, the BSD3 license would have to be
+-- referred to as @self.stdenv.lib.licenses.bsd3@. Other expressions,
+-- however, use different paths to the @licenses@ record.. Because of
+-- this station, this library cannot provide an abstract data type that
+-- encompasses all known licenses. Instead, the @License@ type just
+-- distinguishes references to known and unknown licenses. The
+-- difference between the two is in the way they are pretty-printed:
+--
+-- > > putStrLn (display (Known "stdenv.lib.license.gpl2"))
+-- > stdenv.lib.license.gpl2
+-- >
+-- > > putStrLn (display (Unknown (Just "GPL")))
+-- > "GPL"
+-- >
+-- > > putStrLn (display (Unknown Nothing))
+-- > "unknown"
+--
+-- Note that the "Text" instance definition provides pretty-printing,
+-- but no parsing as of now!
+
+data License = Known String
+             | Unknown (Maybe String)
+  deriving (Show, Eq, Ord)
+
+instance Text License where
+  disp (Known x)   = text x
+  disp (Unknown x) = string (maybe "unknown" id x)
+  parse = error "parsing Distribution.NixOS.Derivation.License is not supported yet"
+
diff --git a/src/Distribution/NixOS/Derivation/Meta.hs b/src/Distribution/NixOS/Derivation/Meta.hs
new file mode 100644
--- /dev/null
+++ b/src/Distribution/NixOS/Derivation/Meta.hs
@@ -0,0 +1,68 @@
+{- |
+   Module      :  Distribution.NixOS.Derivation.Meta
+   License     :  BSD3
+
+   Maintainer  :  nix-dev@cs.uu.nl
+   Stability   :  provisional
+   Portability :  portable
+
+   A representation of the @meta@ section used in Nix expressions. A
+   detailed description can be found in section 4, \"Meta-attributes\",
+   of the Nixpkgs manual at <http://nixos.org/nixpkgs/docs.html>.
+ -}
+
+module Distribution.NixOS.Derivation.Meta
+  ( Meta(..)
+  , module Distribution.NixOS.Derivation.License
+  )
+  where
+
+import Distribution.NixOS.PrettyPrinting
+import Distribution.NixOS.Derivation.License
+import Distribution.Text
+
+-- | A representation of the @meta@ section used in Nix expressions.
+--
+-- > > putStrLn (display (Meta "http://example.org" "an example package" (Unknown Nothing)
+-- > >                   ["stdenv.lib.platforms."++x | x<-["unix","cygwin"]]
+-- > >                   ["stdenv.lib.maintainers."++x | x<-["joe","jane"]]))
+-- > meta = {
+-- >   homepage = "http://example.org";
+-- >   description = "an example package";
+-- >   license = "unknown";
+-- >   platforms =
+-- >     stdenv.lib.platforms.unix ++ stdenv.lib.platforms.cygwin;
+-- >   maintainers = [ stdenv.lib.maintainers.joe stdenv.lib.maintainers.jane ];
+-- > };
+--
+-- Note that the "Text" instance definition provides pretty-printing,
+-- but no parsing as of now!
+
+data Meta = Meta
+  { homepage    :: String       -- ^ URL of the package homepage
+  , description :: String       -- ^ short description of the package
+  , license     :: License      -- ^ licensing terms
+  , platforms   :: [String]     -- ^ list of supported platforms from @pkgs\/lib\/platforms.nix@
+  , maintainers :: [String]     -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
+  }
+  deriving (Show, Eq, Ord)
+
+instance Text Meta where
+  disp  = renderMeta
+  parse = error "parsing Distribution.NixOS.Derivation.Cabal.Meta is not supported yet"
+
+renderMeta :: Meta -> Doc
+renderMeta meta = vcat
+  [ text "meta" <+> equals <+> lbrace
+  , nest 2 $ vcat
+    [ onlyIf (homepage meta) $ attr "homepage" $ string (homepage meta)
+    , onlyIf (description meta) $ attr "description" $ string (description meta)
+    , attr "license" $ disp (license meta)
+    , onlyIf (platforms meta) $ sep
+      [ text "platforms" <+> equals
+      , nest 2 ((fsep $ punctuate (text " ++") $ map text (platforms meta))) <> semi
+      ]
+    , listattr "maintainers" (maintainers meta)
+    ]
+  , rbrace <> semi
+  ]
diff --git a/src/Distribution/NixOS/PrettyPrinting.hs b/src/Distribution/NixOS/PrettyPrinting.hs
new file mode 100644
--- /dev/null
+++ b/src/Distribution/NixOS/PrettyPrinting.hs
@@ -0,0 +1,57 @@
+{- |
+   Module      :  Distribution.NixOS.PrettyPrinting
+   License     :  BSD3
+
+   Maintainer  :  nix-dev@cs.uu.nl
+   Stability   :  provisional
+   Portability :  portable
+
+   Internal pretty-printing helpers for Nix expressions.
+-}
+
+module Distribution.NixOS.PrettyPrinting
+  ( onlyIf
+  , listattr
+  , boolattr
+  , attr
+  , string
+  , funargs
+  , module Text.PrettyPrint
+  )
+  where
+
+import Text.PrettyPrint
+
+attr :: String -> Doc -> Doc
+attr n v = text n <+> equals <+> v <> semi
+
+onlyIf :: [a] -> Doc -> Doc
+onlyIf p d = if not (null p) then d else empty
+
+boolattr :: String -> Bool -> Bool -> Doc
+boolattr n p v = if p then attr n (bool v) else empty
+
+listattr :: String -> [String] -> Doc
+listattr n vs = onlyIf vs $
+                sep [ text n <+> equals <+> lbrack,
+                      nest 2 $ fsep $ map text vs,
+                      rbrack <> semi
+                    ]
+
+bool :: Bool -> Doc
+bool True  = text "true"
+bool False = text "false"
+
+string :: String -> Doc
+string = doubleQuotes . text
+
+prepunctuate :: Doc -> [Doc] -> [Doc]
+prepunctuate _ []     = []
+prepunctuate p (d:ds) = d : map (p <>) ds
+
+funargs :: [Doc] -> Doc
+funargs xs = sep [
+               lbrace <+> (fcat $ prepunctuate (comma <> text " ") $
+                           map (nest 2) xs),
+               rbrace <> colon
+             ]
