git.iko.soy/typeable/cabal2nix
on master help sign in
Merge pull request #370 from kquick/nosub

Add --no-submodules option to suppress fetching submodules (e.g. git).

commitb8dc5b1b16ae633eb8a75a15a83f44131edf611c authorBas van Dijk <v.dijk.bas@gmail.com> dateMon 13 Aug 2018, 12:31 (8 years ago) parente9ffc2ba0cbf2b
3 files changed+23−11
src/Cabal2nix.hs+6−2 src/Distribution/Nixpkgs/Fetch.hs+5−3 src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+12−6
src/Cabal2nix.hs+6−2
@@ -64,6 +64,7 @@ data Options = Options
6464 , optHackageSnapshot :: Maybe UTCTime
6565 , optNixpkgsIdentifier :: NixpkgsResolver
6666 , optUrl :: String
67+ , optFetchSubmodules :: Bool
6768 }
6869
6970options :: Parser Options
@@ -90,6 +91,7 @@ options = Options
9091 <*> optional (option utcTimeReader (long "hackage-snapshot" <> help "hackage snapshot time, ISO format"))
9192 <*> pure (\i -> Just (binding # (i, path # [ident # "pkgs", i])))
9293 <*> strArgument (metavar "URI")
94+ <*> flag True False (long "dont-fetch-submodules" <> help "do not fetch git submodules from git sources")
9395
9496-- | A parser for the date. Hackage updates happen maybe once or twice a month.
9597-- Example: parseTime defaultTimeLocale "%FT%T%QZ" "2017-11-20T12:18:35Z" :: Maybe UTCTime
@@ -187,14 +189,16 @@ hpackOverrides = over phaseOverrides (++ "preConfigure = \"hpack\";")
187189
188190cabal2nix' :: Options -> IO (Either Doc Derivation)
189191cabal2nix' opts@Options{..} = do
190− pkg <- getPackage optHpack optHackageDb optHackageSnapshot $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
192+ pkg <- getPackage optHpack optFetchSubmodules optHackageDb optHackageSnapshot $
193+ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
191194 processPackage opts pkg
192195
193196cabal2nixWithDB :: DB.HackageDB -> Options -> IO (Either Doc Derivation)
194197cabal2nixWithDB db opts@Options{..} = do
195198 when (isJust optHackageDb) $ hPutStrLn stderr "WARN: HackageDB provided directly; ignoring --hackage-db"
196199 when (isJust optHackageSnapshot) $ hPutStrLn stderr "WARN: HackageDB provided directly; ignoring --hackage-snapshot"
197− pkg <- getPackage' optHpack (return db) $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
200+ pkg <- getPackage' optHpack optFetchSubmodules (return db) $
201+ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
198202 processPackage opts pkg
199203
200204processPackage :: Options -> Package -> IO (Either Doc Derivation)
src/Distribution/Nixpkgs/Fetch.hs+5−3
@@ -72,16 +72,18 @@ fromDerivationSource :: DerivationSource -> Source
7272fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision (Certain derivHash) "."
7373
7474-- | Fetch a source, trying any of the various nix-prefetch-* scripts.
75−fetch :: forall a. (String -> MaybeT IO a) -- ^ This function is passed the output path name as an argument.
75+fetch :: forall a.
76+ Bool -- ^ If True, fetch submodules when the source is a git repository
77+ -> (String -> MaybeT IO a) -- ^ This function is passed the output path name as an argument.
7678 -- It should return 'Nothing' if the file doesn't match the expected format.
7779 -- This is required, because we cannot always check if a download succeeded otherwise.
7880 -> Source -- ^ The source to fetch from.
7981 -> IO (Maybe (DerivationSource, a)) -- ^ The derivation source and the result of the processing function. Returns Nothing if the download failed.
80−fetch f = runMaybeT . fetchers where
82+fetch optSubModules f = runMaybeT . fetchers where
8183 fetchers :: Source -> MaybeT IO (DerivationSource, a)
8284 fetchers source = msum . (fetchLocal source :) $ map (\fetcher -> fetchWith fetcher source >>= process)
8385 [ (False, "url", [])
84− , (True, "git", ["--fetch-submodules"])
86+ , (True, "git", ["--fetch-submodules" | optSubModules ])
8587 , (True, "hg", [])
8688 , (True, "svn", [])
8789 , (True, "bzr", [])
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+12−6
@@ -41,35 +41,41 @@ data Package = Package
4141
4242getPackage :: Bool
4343 -- ^ Whether hpack should regenerate the cabal file.
44+ -> Bool
45+ -- ^ Whether to fetch submodules if fetching from git
4446 -> Maybe FilePath
4547 -- ^ The path to the Hackage database.
4648 -> Maybe UTCTime
4749 -- ^ If we have hackage-snapshot time.
4850 -> Source
4951 -> IO Package
50−getPackage optHpack optHackageDB optHackageSnapshot =
51− getPackage' optHpack (loadHackageDB optHackageDB optHackageSnapshot)
52+getPackage optHpack optSubmodules optHackageDB optHackageSnapshot =
53+ getPackage' optHpack optSubmodules (loadHackageDB optHackageDB optHackageSnapshot)
5254
5355getPackage' :: Bool
5456 -- ^ Whether hpack should regenerate the cabal file.
57+ -> Bool
58+ -- ^ Whether to fetch submodules if fetching from git
5559 -> IO DB.HackageDB
5660 -> Source
5761 -> IO Package
58−getPackage' optHpack hackageDB source = do
59− (derivSource, ranHpack, pkgDesc) <- fetchOrFromDB optHpack hackageDB source
62+getPackage' optHpack optSubmodules hackageDB source = do
63+ (derivSource, ranHpack, pkgDesc) <- fetchOrFromDB optHpack optSubmodules hackageDB source
6064 (\s -> Package s ranHpack pkgDesc) <$> maybe (sourceFromHackage (sourceHash source) (showPackageIdentifier pkgDesc) $ sourceCabalDir source) return derivSource
6165
6266fetchOrFromDB :: Bool
6367 -- ^ Whether hpack should regenerate the cabal file
68+ -> Bool
69+ -- ^ Whether to fetch submodules if fetching from git
6470 -> IO DB.HackageDB
6571 -> Source
6672 -> IO (Maybe DerivationSource, Bool, Cabal.GenericPackageDescription)
67−fetchOrFromDB optHpack hackageDB src
73+fetchOrFromDB optHpack optSubmodules hackageDB src
6874 | "cabal://" `isPrefixOf` sourceUrl src = do
6975 (msrc, pkgDesc) <- fromDB hackageDB . drop (length "cabal://") $ sourceUrl src
7076 return (msrc, False, pkgDesc)
7177 | otherwise = do
72− r <- fetch (\dir -> cabalFromPath optHpack (dir </> sourceCabalDir src)) src
78+ r <- fetch optSubmodules (\dir -> cabalFromPath optHpack (dir </> sourceCabalDir src)) src
7379 case r of
7480 Nothing -> fail $ "Failed to fetch source. Does this source exist? " ++ show src
7581 Just (derivSource, (externalSource, ranHpack, pkgDesc)) ->