git.iko.soy/typeable/cabal2nix
on master help sign in
Greatly simplify the hackag2nix utility.
commit9bef967dbe5dd67711c094c1be60ab637d4d8fce authorPeter Simons <simons@cryp.to> dateThu 11 Dec 2014, 15:59 (12 years ago) parent53be170
3 files changed+18−71
cabal2nix.cabal+7−7 release.nix+2−2 src/hackage2nix.hs+9−62
cabal2nix.cabal+7−7
@@ -1,5 +1,5 @@
11Name: cabal2nix
2−Version: 1.73
2+Version: 2.0
33Copyright: Peter Simons, Andres Loeh
44License: BSD3
55License-File: LICENSE
@@ -10,7 +10,7 @@ Category: Distribution
1010Synopsis: Convert Cabal files into Nix build instructions
1111Cabal-Version: >= 1.8
1212Build-Type: Custom
13−Tested-With: GHC >= 7.0.4 && <= 7.8.3
13+Tested-With: GHC == 7.8.3
1414Data-files: README.md
1515Description:
1616 The @cabal2nix@ utility converts Cabal files into Nix build instructions. The
@@ -39,8 +39,8 @@ Description:
3939 .
4040 The only required argument is the path to the cabal file. For example:
4141 .
42− > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.73/cabal2nix.cabal
43− > cabal2nix cabal://cabal2nix-1.73
42+ > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/2.0/cabal2nix.cabal
43+ > cabal2nix cabal://cabal2nix-2.0
4444 .
4545 If the @--sha256@ option has not been specified, cabal2nix calls
4646 @nix-prefetch-url@ to determine the hash automatically. This causes
@@ -103,9 +103,9 @@ Executable hackage4nix
103103Executable hackage2nix
104104 main-is: hackage2nix.hs
105105 hs-source-dirs: src
106− Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.16,
107− mtl, containers, directory, filepath, hackage-db >= 1.11, optparse-applicative >= 0.10,
108− IfElse, transformers, process, monad-par, monad-par-extras, deepseq
106+ Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.18,
107+ filepath, directory, process, hackage-db >= 1.11, transformers, deepseq,
108+ containers, mtl, monad-par, monad-par-extras
109109 Ghc-Options: -Wall -threaded -rtsopts -with-rtsopts=-N
110110 Extensions: PatternGuards, RecordWildCards, CPP
111111 other-modules: Cabal2Nix.CorePackages
release.nix+2−2
@@ -25,8 +25,8 @@ in
2525 isLibrary = false;
2626 isExecutable = true;
2727 buildDepends = with haskellPackages; [
28− Cabal filepath hackageDb IfElse mtl optparseApplicative
29− regexPosix transformers monadPar monadParExtras deepseq
28+ Cabal deepseq filepath hackageDb monadPar monadParExtras mtl
29+ regexPosix transformers
3030 ];
3131 testDepends = with haskellPackages; [ doctest ];
3232 doCheck = nativeCabal;
src/hackage2nix.hs+9−62
@@ -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 }:"