git.iko.soy/typeable/cabal2nix
on master help sign in
Cabal2Nix.hs: added --no-haddock option to disable generation of the Haddock documentation
8680873Peter Simons
src/Cabal2Nix.hs+4−2
@@ -22,7 +22,7 @@ readCabalFile path
22 | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
22 | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
23 | otherwise = readFile path
23 | otherwise = readFile path
24
24
25−data CliOption = PrintHelp | SHA256 String | Maintainer String | Platform String
25+data CliOption = PrintHelp | SHA256 String | Maintainer String | Platform String | NoHaddock
26 deriving (Eq)
26 deriving (Eq)
27
27
28main :: IO ()
28main :: IO ()
@@ -33,6 +33,7 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
33 , Option [] ["sha256"] (ReqArg SHA256 "HASH") "sha256 hash of source tarball"
33 , Option [] ["sha256"] (ReqArg SHA256 "HASH") "sha256 hash of source tarball"
34 , Option ['m'] ["maintainer"] (ReqArg Maintainer "MAINTAINER") "maintainer of this package (may be specified multiple times)"
34 , Option ['m'] ["maintainer"] (ReqArg Maintainer "MAINTAINER") "maintainer of this package (may be specified multiple times)"
35 , Option ['p'] ["platform"] (ReqArg Platform "PLATFORM") "supported build platforms (may be specified multiple times)"
35 , Option ['p'] ["platform"] (ReqArg Platform "PLATFORM") "supported build platforms (may be specified multiple times)"
36+ , Option [] ["no-haddock"] (NoArg NoHaddock) "don't run Haddock when building this package"
36 ]
37 ]
37
38
38 usage :: String
39 usage :: String
@@ -58,6 +59,7 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
58
59
59 let uri = args
60 let uri = args
60 hash = [ h | SHA256 h <- opts ]
61 hash = [ h | SHA256 h <- opts ]
62+ noHaddock = NoHaddock `elem` opts
61 maintainers = [ m | Maintainer m <- opts ]
63 maintainers = [ m | Maintainer m <- opts ]
62 platforms' = [ p | Platform p <- opts ]
64 platforms' = [ p | Platform p <- opts ]
63 platforms
65 platforms
@@ -78,4 +80,4 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
78
80
79 sha256 <- if null hash then hashPackage packageId else return (head hash)
81 sha256 <- if null hash then hashPackage packageId else return (head hash)
80
82
81− putStr (showNixPkg (cabal2nix cabal sha256 platforms maintainers))
83+ putStr (showNixPkg (cabal2nix cabal sha256 noHaddock platforms maintainers))
src/Cabal2Nix/Package.hs+8−4
@@ -2,7 +2,7 @@ module Cabal2Nix.Package
2 ( cabal2nix, showNixPkg
2 ( cabal2nix, showNixPkg
3 , PkgName, PkgVersion, PkgSHA256, PkgURL, PkgDescription, PkgLicense
3 , PkgName, PkgVersion, PkgSHA256, PkgURL, PkgDescription, PkgLicense
4 , PkgIsLib, PkgIsExe, PkgDependencies, PkgBuildTools, PkgExtraLibs
4 , PkgIsLib, PkgIsExe, PkgDependencies, PkgBuildTools, PkgExtraLibs
5− , PkgPkgconfigDeps, PkgPlatforms, PkgMaintainers, Pkg(..)
5+ , PkgPkgconfigDeps, PkgPlatforms, PkgMaintainers, PkgNoHaddock, Pkg(..)
6 )
6 )
7 where
7 where
8
8
@@ -34,6 +34,7 @@ type PkgDependencies = [Dependency] -- [CondTree ConfVar [Dependency] ()]
34type PkgBuildTools = [Dependency]
34type PkgBuildTools = [Dependency]
35type PkgExtraLibs = [String]
35type PkgExtraLibs = [String]
36type PkgPkgconfigDeps = [String]
36type PkgPkgconfigDeps = [String]
37+type PkgNoHaddock = Bool
37type PkgPlatforms = [String]
38type PkgPlatforms = [String]
38type PkgMaintainers = [String]
39type PkgMaintainers = [String]
39
40
@@ -49,13 +50,14 @@ data Pkg = Pkg PkgName
49 PkgBuildTools
50 PkgBuildTools
50 PkgExtraLibs
51 PkgExtraLibs
51 PkgPkgconfigDeps
52 PkgPkgconfigDeps
53+ PkgNoHaddock
52 PkgPlatforms
54 PkgPlatforms
53 PkgMaintainers
55 PkgMaintainers
54 deriving (Show)
56 deriving (Show)
55
57
56showNixPkg :: Pkg -> String
58showNixPkg :: Pkg -> String
57showNixPkg (Pkg name ver sha256 url desc lic isLib isExe deps
59showNixPkg (Pkg name ver sha256 url desc lic isLib isExe deps
58− tools libs pcs platforms maintainers) =
60+ tools libs pcs noHaddock platforms maintainers) =
59 render doc
61 render doc
60 where
62 where
61 doc = funargs (map text ("cabal" : pkgInputs)) $$
63 doc = funargs (map text ("cabal" : pkgInputs)) $$
@@ -73,6 +75,7 @@ showNixPkg (Pkg name ver sha256 url desc lic isLib isExe deps
73 listattr "buildTools" pkgBuildTools,
75 listattr "buildTools" pkgBuildTools,
74 listattr "extraLibraries" pkgLibs,
76 listattr "extraLibraries" pkgLibs,
75 listattr "pkgconfigDepends" pkgPCs,
77 listattr "pkgconfigDepends" pkgPCs,
78+ boolattr "noHaddock" noHaddock noHaddock,
76 vcat [
79 vcat [
77 text "meta" <+> equals <+> lbrace,
80 text "meta" <+> equals <+> lbrace,
78 nest 2 $ vcat [
81 nest 2 $ vcat [
@@ -101,14 +104,15 @@ showNixPkg (Pkg name ver sha256 url desc lic isLib isExe deps
101 pkgInputs = nub $ pkgLibs ++ pkgPCs ++ pkgBuildTools ++ pkgDeps
104 pkgInputs = nub $ pkgLibs ++ pkgPCs ++ pkgBuildTools ++ pkgDeps
102
105
103
106
104−cabal2nix :: GenericPackageDescription -> PkgSHA256 -> PkgPlatforms -> PkgMaintainers -> Pkg
107+cabal2nix :: GenericPackageDescription -> PkgSHA256 -> PkgNoHaddock -> PkgPlatforms -> PkgMaintainers -> Pkg
105−cabal2nix cabal sha256 platforms maintainers =
108+cabal2nix cabal sha256 noHaddock platforms maintainers =
106 Pkg pkgname pkgver sha256 url desc lic
109 Pkg pkgname pkgver sha256 url desc lic
107 isLib isExe
110 isLib isExe
108 (buildDepends tpkg)
111 (buildDepends tpkg)
109 tools
112 tools
110 libs
113 libs
111 pcs
114 pcs
115+ noHaddock
112 [ if '.' `elem` p then p else "self.stdenv.lib.platforms." ++ p | p <- platforms ]
116 [ if '.' `elem` p then p else "self.stdenv.lib.platforms." ++ p | p <- platforms ]
113 [ if '.' `elem` m then m else "self.stdenv.lib.maintainers." ++ m | m <- maintainers ]
117 [ if '.' `elem` m then m else "self.stdenv.lib.maintainers." ++ m | m <- maintainers ]
114 where
118 where