@@ -1,5 +1,3 @@
1−{-# LANGUAGE Rank2Types #-}
2−
31-- Run: cabal build -j hackage2nix && dist/build/hackage2nix/hackage2nix >hackage-packages.nix
42
53module Main ( main ) where
@@ -7,11 +5,11 @@ module Main ( main ) where
75import Cabal2Nix.Generate
86import Cabal2Nix.Name
97import Cabal2Nix.Package
10−import Control.Monad.IfElse
8+import Control.Monad
119import Control.Monad.Par.Combinator
1210import Control.Monad.Par.IO
13−import Control.Monad.Reader
14−import Control.Monad.State.Strict hiding ( State )
11+import Control.Monad.Trans
12+import Data.Map ( Map )
1513import qualified Data.Map as Map
1614import Data.Monoid
1715import qualified Data.Set as Set
@@ -19,68 +17,17 @@ import Distribution.Hackage.DB ( Hackage, readHackage, GenericPackageDescription
1917import Distribution.NixOS.Derivation.Cabal
2018import Distribution.NixOS.PrettyPrinting hiding ( (<>) )
2119import Distribution.Text
22−import Options.Applicative
23−import System.IO
24−
25−type Map = Map.Map
26−
27−data Options = Options
28− { verbose :: Bool
29− }
30− deriving (Show)
31−
32−data Config = Config
33− { _verbose :: Bool
34− , _hackage :: Hackage
35− }
36− deriving (Show)
37−
38−type Compile a = (Functor m, MonadIO m) => StateT () (ReaderT Config m) a
39−
40−yell :: String -> Compile ()
41−yell = liftIO . hPutStrLn stderr
42−
43−msgInfo, msgNote, msgWarn :: String -> Compile ()
44−msgInfo = whenM (asks _verbose) . yell . showString "INFO: "
45−msgNote = yell . showString "NOTE: "
46−msgWarn = yell . showString "WARN: "
47−
48−runCompiler :: (Functor m, MonadIO m) => Compile a -> Options -> m a
49−runCompiler f opts = do
50− db <- liftIO readHackage
51− let cfg = Config
52− { _verbose = verbose opts
53− , _hackage = db
54− }
55− st = ()
56− f' = msgInfo (showString "options = " (show opts)) >> f
57− runReaderT (evalStateT f' st) cfg
58−
59−-- | A convenience variant of 'runCompiler' that's probably good enough
60−-- for quick-fire testing in ghci.
61−run :: Compile a -> IO a
62−run f = runCompiler f Options { verbose = True }
6320
6421main :: IO ()
65−main = execParser mainOptions >>= runCompiler buildPackageSet
66− where
67− parseOptions :: Parser Options
68− parseOptions = Options
69− <$> switch (long "verbose" <> help "enable detailed progress diagnostics")
70−
71− mainOptions :: ParserInfo Options
72− mainOptions = info (helper <*> parseOptions)
73− ( fullDesc
74− <> header "hackage2nix -- convert the Hackage database into Nix build instructions"
75− )
22+main = readHackage >>= runParIO . generatePackageSet
7623
7724nixAttr :: String -> Version -> String
78−nixAttr name ver = show $ toNixName name -- ++ "_" ++ [ if c == '.' then '_' else c | c <- display ver ]
25+nixAttr name _ = show $ toNixName name -- ++ "_" ++ [ if c == '.' then '_' else c | c <- display ver ]
7926
80−buildPackageSet :: Compile ()
81−buildPackageSet = do
82− db <- fmap (\db -> foldr Map.delete db ["smtLib", "testPkg"]) (asks _hackage)
83− pkgs <- liftIO $ runParIO $ parMapM generatePackage (Map.toList db)
27+generatePackageSet :: Hackage -> ParIO ()
28+generatePackageSet db' = do
29+ let db = foldr Map.delete db' ["smtLib", "testPkg"]
30+ pkgs <- parMapM generatePackage (Map.toList db)
8431 liftIO $ putStrLn "/* hackage-packages.nix is an auto-generated file -- DO NOT EDIT! */"
8532 liftIO $ putStrLn ""
8633 liftIO $ putStrLn "{ stdenv, ghc, pkgs, definePackage }:"