diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -10,13 +10,12 @@
       pname = "mtl";
       version = "2.2.1";
       sha256 = "1icdbj2rshzn0m1zz5wa7v3xvkf6qw811p4s7jgqwvx1ydwrvrfa";
-      buildDepends = [ base transformers ];
+      libraryHaskellDepends = [ base transformers ];
       homepage = "http://github.com/ekmett/mtl";
       description = "Monad classes, using functional dependencies";
       license = stdenv.lib.licenses.bsd3;
     }
 
-
 Cabal files can be referred to using the magic URL `cabal://NAME-VERSION`,
 which will automatically download the file from Hackage. Alternatively, a
 direct `http://host/path/pkg.cabal` URL can be provided, as well as a
@@ -41,7 +40,7 @@
       pname = "mtl";
       version = "2.2.1";
       src = ./.;
-      buildDepends = [ base transformers ];
+      libraryHaskellDepends = [ base transformers ];
       homepage = "http://github.com/ekmett/mtl";
       description = "Monad classes, using functional dependencies";
       license = stdenv.lib.licenses.bsd3;
@@ -55,30 +54,3 @@
 * directory
 * source archive (zip, tar.gz, ...) from http or https URL or local file.
 * git, mercurial, svn or bazaar repository
-
-How to compile this package
----------------------------
-
-The `cabal2nix.cabal` file for this package is automatically generated by the
-`generate-cabal-file.hs` program. The easiest way to accomplish that is to run
-
-    nix-shell release.nix -A cabal2nix.ghc7102.x86_64-linux.env --run "runhaskell generate-cabal-file.hs >cabal2nix.cabal"
-
-where `x86_64-linux` should be replaced with whatever system ID is appropriate
-for your local machine. Basically, `generate-cabal-file.hs` requires the
-[cartel](http://hackage.haskell.org/package/cartel) library and `git` to run.
-
-With the Cabal file in place, this is a normal Haskell project that can be
-compiled with `cabal-install`.
-
-Users of Nix can build this package by running
-
-    nix-build release.nix -A cabal2nix.ghc7102.x86_64-linux
-
-where, again, `x86_64-linux` should be replaced with the appropriate value.
-This gives you an executable at `result/bin/cabal2nix`. If you'd like to
-install the latest release version, then
-
-    nix-env -f "<nixpkgs>" -iA cabal2nix
-
-is the way to go.
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.1.1
+version:        2.2
 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:
                 .
@@ -16,39 +16,48 @@
                 Andres Loeh,
                 Benno Fünfstück,
                 Mateusz Kowalczyk,
-                Mathijs Kwik,
                 Michael Alan Dorman,
+                Mathijs Kwik,
                 Shea Levy,
                 Dmitry Malikov,
                 Eric Seidel,
+                Hamish Mackenzie,
                 Nikolay Amiantov,
                 Aycan iRiCAN,
+                Bryan Gardiner,
+                Joe Hermaszewski,
                 John Wiegley,
                 Philipp Hausmann,
                 Spencer Janssen,
+                Tom Hunger,
                 William Casarin,
+                koral,
                 Adam Vogt,
-                Bryan Gardiner,
+                Alexey Shmalko,
                 Corey O'Connor,
                 Cray Elliott,
                 Felix Kunzmann,
                 Gabriel Ebner,
                 Gergely Risko,
+                Jacob Mitchell,
+                Joachim Fasting,
                 John Albietz,
                 John Chee,
                 Jussi Maki,
                 Mark Laws,
                 Mark Wotton,
+                Matthew Stewart,
                 Matvey Aksenov,
                 Nicolas Rolland,
                 Oliver Charles,
                 Pascal Wittmann,
                 Patrick John Wheeler,
+                Profpatsch,
                 Raymond Gauthier,
                 Renzo Carbonara,
+                Rodney Lorrimar,
                 Sibi,
                 Tanner Doshier,
-                Tom Hunger,
                 Viktar Basharymau,
                 danbst,
                 karsten gebbert,
diff --git a/cabal2nix/Main.hs b/cabal2nix/Main.hs
--- a/cabal2nix/Main.hs
+++ b/cabal2nix/Main.hs
@@ -45,6 +45,7 @@
   , optFlags :: [String]
   , optCompiler :: CompilerId
   , optSystem :: Platform
+  , optSubpath :: Maybe FilePath
   , optUrl :: String
   }
   deriving (Show)
@@ -68,6 +69,7 @@
           <*> many (strOption $ short 'f' <> long "flag" <> help "Cabal flag (may be specified multiple times)")
           <*> option (readP parse) (long "compiler" <> help "compiler to use when evaluating the Cabal file" <> value buildCompilerId <> showDefaultWith display)
           <*> option (readP parsePlatform) (long "system" <> help "target system to use when evaluating the Cabal file" <> value buildPlatform <> showDefaultWith display)
+          <*> optional (strOption $ long "subpath" <> metavar "PATH" <> help "Path to Cabal file's directory relative to the URI (default is root directory)")
           <*> strArgument (metavar "URI")
 
 readP :: P.ReadP a a -> ReadM a
@@ -112,7 +114,7 @@
 main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
   Options {..} <- execParser pinfo
 
-  pkg <- getPackage optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256)
+  pkg <- getPackage optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "." optSubpath)
 
   let
       deriv :: Derivation
@@ -124,6 +126,7 @@
                                             []
                                             (pkgCabal pkg)
               & src .~ pkgSource pkg
+              & subpath .~ (fromMaybe "." optSubpath)
               & runHaddock .~ optHaddock
               & jailbreak .~ optJailbreak
               & hyperlinkSource .~ optHyperlinkSource
diff --git a/src/Distribution/Nixpkgs/Fetch.hs b/src/Distribution/Nixpkgs/Fetch.hs
--- a/src/Distribution/Nixpkgs/Fetch.hs
+++ b/src/Distribution/Nixpkgs/Fetch.hs
@@ -31,6 +31,7 @@
   , sourceRevision  :: String       -- ^ Revision to use. For protocols where this doesn't make sense (such as HTTP), this
                                     --   should be the empty string.
   , sourceHash      :: Hash         -- ^ The expected hash of the source, if available.
+  , sourceCabalDir  :: String       -- ^ Directory where Cabal file is found.
   } deriving (Show, Eq, Ord, Generic)
 
 instance NFData Source
@@ -68,7 +69,7 @@
   parseJSON _ = error "invalid DerivationSource"
 
 fromDerivationSource :: DerivationSource -> Source
-fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision $ Certain derivHash
+fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision (Certain derivHash) "."
 
 -- | Fetch a source, trying any of the various nix-prefetch-* scripts.
 fetch :: forall a. (String -> MaybeT IO a)      -- ^ This function is passed the output path name as an argument.
@@ -104,7 +105,7 @@
   localArchive :: FilePath -> MaybeT IO (DerivationSource, a)
   localArchive path = do
     absolutePath <- liftIO $ canonicalizePath path
-    unpacked <- snd <$> fetchWith (False, "zip", []) (Source ("file://" ++ absolutePath) "" UnknownHash)
+    unpacked <- snd <$> fetchWith (False, "zip", []) (Source ("file://" ++ absolutePath) "" UnknownHash ".")
     process (DerivationSource "" absolutePath "" "", unpacked)
 
   process :: (DerivationSource, FilePath) -> MaybeT IO (DerivationSource, a)
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
@@ -4,7 +4,7 @@
 {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
 
 module Distribution.Nixpkgs.Haskell.Derivation
-  ( Derivation, nullDerivation, pkgid, revision, src, isLibrary, isExecutable
+  ( Derivation, nullDerivation, pkgid, revision, src, subpath, isLibrary, isExecutable
   , extraFunctionArgs, libraryDepends, executableDepends, testDepends, configureFlags
   , cabalFlags, runHaddock, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
   , enableLibraryProfiling, enableExecutableProfiling, phaseOverrides, editedCabalFile, metaSection
@@ -36,6 +36,7 @@
   { _pkgid                      :: PackageIdentifier
   , _revision                   :: Int
   , _src                        :: DerivationSource
+  , _subpath                    :: FilePath
   , _isLibrary                  :: Bool
   , _isExecutable               :: Bool
   , _extraFunctionArgs          :: Set Binding
@@ -65,6 +66,7 @@
   { _pkgid = error "undefined Derivation.pkgid"
   , _revision = error "undefined Derivation.revision"
   , _src = error "undefined Derivation.src"
+  , _subpath = error "undefined Derivation.subpath"
   , _isLibrary = error "undefined Derivation.isLibrary"
   , _isExecutable = error "undefined Derivation.isExecutable"
   , _extraFunctionArgs = error "undefined Derivation.extraFunctionArgs"
@@ -104,6 +106,7 @@
       [ attr "pname"   $ doubleQuotes $ disp (packageName _pkgid)
       , attr "version" $ doubleQuotes $ disp (packageVersion _pkgid)
       , sourceAttr _src
+      , onlyIf (_subpath /= ".") $ attr "postUnpack" postUnpack
       , onlyIf (_revision > 0) $ attr "revision" $ doubleQuotes $ int _revision
       , onlyIf (not (null _editedCabalFile) && _revision > 0) $ attr "editedCabalFile" $ string _editedCabalFile
       , listattr "configureFlags" empty (map (show . show) renderedFlags)
@@ -149,3 +152,5 @@
            , rbrace <> semi
            ]
         | otherwise = attr "src" $ text derivUrl
+
+      postUnpack = string $ "sourceRoot+=/" ++ _subpath ++ "; echo source root reset to $sourceRoot"
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
@@ -103,6 +103,7 @@
       | i `elem` ["clang","lldb","llvm"] = binding # (i, path # ["self","llvmPackages",i])     -- TODO: evil!
       | i == "gtk2"                      = binding # (i, path # ["pkgs","gnome2","gtk"])
       | i == "gtk3"                      = binding # (i, path # ["pkgs","gnome3","gtk"])
+      | i == "gtksourceview3"            = binding # (i, path # ["pkgs","gnome3","gtksourceview"])
       | Just p <- nixpkgsResolver i, init (view (reference . path) p) `Set.member` goodScopes = p
       | otherwise                        = bindNull i
 
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,7 +1,9 @@
 module Distribution.Nixpkgs.Haskell.FromCabal.License ( fromCabalLicense ) where
 
 import Distribution.Nixpkgs.License
-import Distribution.License ( License(..) )
+import Distribution.License ( License(..), knownLicenses )
+import Distribution.Text (display)
+import Data.List (intercalate)
 import Data.Version
 
 -- TODO: Programatically strip trailing zeros from license version numbers.
@@ -31,4 +33,5 @@
 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
+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
@@ -70,6 +70,7 @@
 libNixName "gtk+-2.0"                           = return "gtk2"
 libNixName "gtk+-3.0"                           = return "gtk3"
 libNixName "gtk-x11-2.0"                        = return "gtk_x11"
+libNixName "gtksourceview-3.0"                  = return "gtksourceview3"
 libNixName "hidapi-libusb"                      = return "hidapi"
 libNixName "icudata"                            = return "icu"
 libNixName "icui18n"                            = return "icu"
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
@@ -38,11 +38,13 @@
   , ("Agda >= 2.5", set (executableDepends . tool . contains (pkg "emacs")) True . set phaseOverrides agda25PostInstall)
   , ("alex < 3.1.5",  set (testDepends . tool . contains (pkg "perl")) True)
   , ("alex",  set (executableDepends . tool . contains (bind "self.happy")) True)
+  , ("alsa-core", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os == Linux)))                                                                                                      , ("bustle", set (libraryDepends . pkgconfig . contains "system-glib = pkgs.glib") True)
   , ("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
@@ -50,40 +52,40 @@
   , ("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
-  , ("gi-pango", giCairoPhaseOverrides)                     -- https://github.com/haskell-gi/haskell-gi/issues/36
-  , ("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
+  , ("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)
   , ("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
   , ("GlomeVec", set (libraryDepends . pkgconfig . contains (bind "self.llvmPackages.llvm")) True)
   , ("goatee-gtk", over (metaSection . platforms) (Set.filter (\(Platform _ os) -> os /= OSX)))
   , ("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)
-  , ("HFuse", set phaseOverrides hfusePreConfigure)
   , ("hfsevents", hfseventsOverrides)
+  , ("HFuse", set phaseOverrides hfusePreConfigure)
   , ("hlibgit2 >= 0.18.0.14", set (testDepends . tool . contains (pkg "git")) True)
   , ("hmatrix", set phaseOverrides "preConfigure = \"sed -i hmatrix.cabal -e 's@/usr/@/dont/hardcode/paths/@'\";")
   , ("holy-project", set doCheck False)         -- attempts to access the network
   , ("hoogle", set testTarget "--test-option=--no-net")
   , ("hsignal < 0.2.7.4", set phaseOverrides "prePatch = \"rm -v Setup.lhs\";") -- https://github.com/amcphail/hsignal/issues/1
   , ("hslua", over (libraryDepends . each) (replace (pkg "lua") (pkg "lua5_1")))
-  , ("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", 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
   , ("include-file <= 0.1.0.2", set (libraryDepends . haskell . contains (bind "self.random")) True) -- https://github.com/Daniel-Diaz/include-file/issues/1
-  , ("js-jquery", set doCheck False)            -- attempts to access the network
   , ("jsaddle", set (dependencies . haskell . contains (bind "self.ghcjs-base")) False)
+  , ("js-jquery", set doCheck False)            -- attempts to access the network
   , ("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)
@@ -92,11 +94,11 @@
   , ("mysql", set (libraryDepends . system . contains (pkg "mysql")) True)
   , ("network-attoparsec", set doCheck False) -- test suite requires network access
   , ("numeric-qq", set doCheck False) -- test suite doesn't finish even after 1+ days
-  , ("pandoc", set jailbreak False) -- jailbreak-cabal break the build
+  , ("opencv", set phaseOverrides "hardeningDisable = [ \"bindnow\" ];")
   , ("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
   , ("purescript", set doCheck False) -- test suite doesn't cope with Nix build env
-  , ("opencv", set phaseOverrides "hardeningDisable = [ \"bindnow\" ];")
   , ("qtah-cpp-qt5", set (libraryDepends . system . contains (bind "pkgs.qt5.qtbase")) True)
   , ("qtah-qt5", set (libraryDepends . tool . contains (bind "pkgs.qt5.qtbase")) True)
   , ("readline", over (libraryDepends . system) (Set.union (pkgs ["readline", "ncurses"])))
@@ -112,13 +114,14 @@
   , ("thyme", set (libraryDepends . tool . contains (bind "self.cpphs")) True) -- required on Darwin
   , ("twilio", set doCheck False)         -- attempts to access the network
   , ("tz", set phaseOverrides "preConfigure = \"export TZDIR=${pkgs.tzdata}/share/zoneinfo\";")
-  , ("webkitgtk3", webkitgtk24xHook)   -- https://github.com/haskell-gi/haskell-gi/issues/36
+  , ("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
   , ("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)))
-  , ("wxc", wxcHook)
   , ("wxcore", set (libraryDepends . pkgconfig . contains (pkg "wxGTK")) True)
+  , ("wxc", wxcHook)
   , ("X11", over (libraryDepends . system) (Set.union (Set.fromList $ map bind ["pkgs.xorg.libXinerama","pkgs.xorg.libXext","pkgs.xorg.libXrender"])))
   , ("xmonad", set phaseOverrides xmonadPostInstall)
   , ("zip-archive", over (testDepends . tool) (replace (bind "self.zip") (pkg "zip")))
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
@@ -32,18 +32,18 @@
 getPackage :: Maybe String -> Source -> IO Package
 getPackage optHackageDB source = do
   (derivSource, pkgDesc) <- fetchOrFromDB optHackageDB source
-  flip Package pkgDesc <$> maybe (sourceFromHackage (sourceHash source) $ showPackageIdentifier pkgDesc) return derivSource
+  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
   | otherwise                             = do
-    r <- fetch cabalFromPath src
+    r <- fetch (\dir -> cabalFromPath (dir </> sourceCabalDir src)) src
     case r of
       Nothing ->
         hPutStrLn stderr "*** failed to fetch source. Does the URL exist?" >> exitFailure
-      Just (derivSource, (externalSource, pkgDesc)) ->
+      Just (derivSource, (externalSource, pkgDesc)) -> do
         return (derivSource <$ guard externalSource, pkgDesc)
 
 fromDB :: Maybe String -> String -> IO Cabal.GenericPackageDescription
@@ -77,8 +77,8 @@
   createDirectoryIfMissing True cacheDir
   return $ cacheDir </> pid <.> "sha256"
 
-sourceFromHackage :: Hash -> String -> IO DerivationSource
-sourceFromHackage optHash pkgId = do
+sourceFromHackage :: Hash -> String -> String -> IO DerivationSource
+sourceFromHackage optHash pkgId cabalDir = do
   cacheFile <- hashCachePath pkgId
   cachedHash <-
     case optHash of
@@ -99,7 +99,7 @@
       seq (length hash) $
       DerivationSource "url" url "" hash <$ writeFile cacheFile hash
     UnknownHash -> do
-      maybeHash <- runMaybeT (derivHash . fst <$> fetchWith (False, "url", []) (Source url "" UnknownHash))
+      maybeHash <- runMaybeT (derivHash . fst <$> fetchWith (False, "url", []) (Source url "" UnknownHash cabalDir))
       case maybeHash of
         Just hash ->
           seq (length hash) $
@@ -133,7 +133,7 @@
   cabals <- liftIO $ getDirectoryContents dir >>= filterM doesFileExist . map (dir </>) . filter (".cabal" `isSuffixOf`)
   case cabals of
     [cabalFile] -> cabalFromFile True cabalFile
-    _       -> liftIO $ hPutStrLn stderr "*** found zero or more than one cabal file. Exiting." >> exitFailure
+    _       -> liftIO $ hPutStrLn stderr ("*** found zero or more than one cabal file (" ++ show cabals ++ "). Exiting.") >> exitFailure
 
 handleIO :: (Exception.IOException -> IO a) -> IO a -> IO a
 handleIO = Exception.handle
