git.iko.soy/typeable/cabal2nix
on master help sign in
Build tools support.
aa76621Andres Loeh
@@ -1,11 +1,15 @@
1* Should we use the github issue tracker for this?
1* Should we use the github issue tracker for this?
2
2
3+[[
3* Include build-tools field in the list of dependencies.
4* Include build-tools field in the list of dependencies.
4
5
5 Example: haskell-src-exts/1.11.1/haskell-src-exts.cabal needs this.
6 Example: haskell-src-exts/1.11.1/haskell-src-exts.cabal needs this.
6
7
7 +1, this is important.
8 +1, this is important.
8
9
10+ Done.
11+]]
12+
9* Allow patching the cabal file before processing it. This is required
13* Allow patching the cabal file before processing it. This is required
10 to enable/disable cabal flags.
14 to enable/disable cabal flags.
11
15
src/Cabal2Nix/Package.hs+19−6
@@ -21,6 +21,7 @@ type PkgURL = String
21type PkgDescription = String
21type PkgDescription = String
22type PkgLicense = License
22type PkgLicense = License
23type PkgDependencies = [Dependency] -- [CondTree ConfVar [Dependency] ()]
23type PkgDependencies = [Dependency] -- [CondTree ConfVar [Dependency] ()]
24+type PkgBuildTools = [Dependency]
24type PkgExtraLibs = [String]
25type PkgExtraLibs = [String]
25type PkgPlatforms = [String]
26type PkgPlatforms = [String]
26type PkgMaintainers = [String]
27type PkgMaintainers = [String]
@@ -32,15 +33,17 @@ data Pkg = Pkg PkgName
32 PkgDescription
33 PkgDescription
33 PkgLicense
34 PkgLicense
34 PkgDependencies
35 PkgDependencies
36+ PkgBuildTools
35 PkgExtraLibs
37 PkgExtraLibs
36 PkgPlatforms
38 PkgPlatforms
37 PkgMaintainers
39 PkgMaintainers
38 deriving (Show)
40 deriving (Show)
39
41
40showNixPkg :: Pkg -> String
42showNixPkg :: Pkg -> String
41−showNixPkg (Pkg name ver sha256 url desc lic deps libs platforms maintainers) = render doc
43+showNixPkg (Pkg name ver sha256 url desc lic deps tools libs platforms maintainers) = render doc
42 where
44 where
43− doc = braces (fsep $ punctuate comma $ map text ("cabal" : pkgDeps)) <+>
45+ doc = braces (fsep $ punctuate comma $
46+ map text ("cabal" : pkgBuildTools ++ pkgDeps)) <+>
44 colon $$ text "" $$
47 colon $$ text "" $$
45 vcat [
48 vcat [
46 text "cabal.mkDerivation" <+> lparen <> text "self" <+>
49 text "cabal.mkDerivation" <+> lparen <> text "self" <+>
@@ -49,6 +52,12 @@ showNixPkg (Pkg name ver sha256 url desc lic deps libs platforms maintainers) =
49 attr "pname" $ doubleQuotes (text name),
52 attr "pname" $ doubleQuotes (text name),
50 attr "version" $ doubleQuotes showVer,
53 attr "version" $ doubleQuotes showVer,
51 attr "sha256" $ doubleQuotes (text sha256),
54 attr "sha256" $ doubleQuotes (text sha256),
55+ onlyIf pkgBuildTools $
56+ sep [
57+ text "extraBuildInputs" <+> equals <+> lbrack,
58+ nest 2 $ fsep $ map text pkgBuildTools,
59+ rbrack <> semi
60+ ],
52 onlyIf pkgDeps $
61 onlyIf pkgDeps $
53 sep [
62 sep [
54 text "propagatedBuildInputs" <+> equals <+> lbrack,
63 text "propagatedBuildInputs" <+> equals <+> lbrack,
@@ -86,12 +95,15 @@ showNixPkg (Pkg name ver sha256 url desc lic deps libs platforms maintainers) =
86 pkgDeps = (nub $ sort $ map libNixName libs) ++
95 pkgDeps = (nub $ sort $ map libNixName libs) ++
87 (nub $ sort $ map toNixName $
96 (nub $ sort $ map toNixName $
88 filter (`notElem` (name : corePackages)) $ map unDep deps)
97 filter (`notElem` (name : corePackages)) $ map unDep deps)
98+ pkgBuildTools :: [String]
99+ pkgBuildTools = nub $ sort $ map toNixName $ map unDep tools
89
100
90
101
91cabal2nix :: GenericPackageDescription -> PkgSHA256 -> PkgPlatforms -> PkgMaintainers -> Pkg
102cabal2nix :: GenericPackageDescription -> PkgSHA256 -> PkgPlatforms -> PkgMaintainers -> Pkg
92cabal2nix cabal sha256 platforms maintainers =
103cabal2nix cabal sha256 platforms maintainers =
93 Pkg pkgname pkgver sha256 url desc lic
104 Pkg pkgname pkgver sha256 url desc lic
94 (buildDepends tpkg)
105 (buildDepends tpkg)
106+ tools
95 libs
107 libs
96 [ "self.stdenv.lib.platforms." ++ p | p <- platforms ]
108 [ "self.stdenv.lib.platforms." ++ p | p <- platforms ]
97 [ "self.stdenv.lib.maintainers." ++ m | m <- maintainers ]
109 [ "self.stdenv.lib.maintainers." ++ m | m <- maintainers ]
@@ -112,11 +124,12 @@ cabal2nix cabal sha256 platforms maintainers =
112 [] cabal
124 [] cabal
113 libDeps = map libBuildInfo $ maybeToList (library tpkg)
125 libDeps = map libBuildInfo $ maybeToList (library tpkg)
114 exeDeps = map buildInfo $ executables tpkg
126 exeDeps = map buildInfo $ executables tpkg
115− libsExtra = concatMap extraLibs (libDeps ++ exeDeps)
127+ libsExtra = concatMap extraLibs (libDeps ++ exeDeps)
116− libsPkgC = map unDep $ concatMap pkgconfigDepends (libDeps ++ exeDeps)
128+ libsPkgCfg = map unDep $ concatMap pkgconfigDepends (libDeps ++ exeDeps)
129+ tools = concatMap buildTools (libDeps ++ exeDeps)
117 -- add pkgconfig as an extra dependency if there are any pkgconfig deps
130 -- add pkgconfig as an extra dependency if there are any pkgconfig deps
118− libs = libsExtra ++ (if null libsPkgC then []
131+ libs = libsExtra ++ (if null libsPkgCfg then []
119− else ("pkgconfig" : libsPkgC))
132+ else ("pkgconfig" : libsPkgCfg))
120
133
121unDep :: Dependency -> String
134unDep :: Dependency -> String
122unDep (Dependency (PackageName x) _) = x
135unDep (Dependency (PackageName x) _) = x