@@ -1,9 +1,11 @@
11module Cabal2Nix.Package where
22
33import Data.List
4+import Data.Maybe
45
56import Distribution.Package
67import Distribution.PackageDescription
8+import Distribution.Version
79
810import Cabal2Nix.License
911import Cabal2Nix.Name
@@ -51,3 +53,22 @@ toNix (Pkg name ver sha256 url desc lic deps libs) =
5153 , n `notElem` ["base","containers"]
5254 ]
5355
56+cabal2nix :: GenericPackageDescription -> PkgSHA256 -> Pkg
57+cabal2nix cabal sha256 = Pkg pkgname pkgver sha256 url desc lic (map simplify libDeps ++ map simplify exeDeps) (libs++libs')
58+ where
59+ pkg = packageDescription cabal
60+ PackageName pkgname = pkgName (package pkg)
61+ pkgver = versionBranch (pkgVersion (package pkg))
62+ lic = license pkg
63+ url = homepage pkg
64+ desc = synopsis pkg
65+ -- globalDeps = buildDepends pkg
66+ libDeps = maybeToList (condLibrary cabal)
67+ exeDeps = [ tree | (_,tree) <- condExecutables cabal ]
68+ libs = concat [ extraLibs (libBuildInfo (condTreeData x)) | x <- libDeps ]
69+ libs' = concat [ extraLibs (buildInfo (condTreeData x)) | x <- exeDeps ]
70+
71+simplify :: CondTree ConfVar [Dependency] a -> CondTree ConfVar [Dependency] ()
72+simplify (CondNode _ deps nodes) = CondNode () deps (map simp nodes)
73+ where
74+ simp (cond,tree,mtree) = (cond, simplify tree, maybe Nothing (Just . simplify) mtree)