git.iko.soy/typeable/cabal2nix
on master help sign in
Condtree resolution, pkgconfig depends.
commit67762fc6a6c3acf5c79aba9579b7aea6f4c856a3 authorAndres Loeh <mail@andres-loeh.de> dateSun 7 Aug 2011, 13:06 (15 years ago) parent1c9bfae
2 files changed+44−19
src/Cabal2Nix/Name.hs+19−7 src/Cabal2Nix/Package.hs+25−12
src/Cabal2Nix/Name.hs+19−7
@@ -16,10 +16,22 @@ toNixName name = f name
1616-- possibility of name clashes with Haskell libraries. I have included
1717-- identity mappings to incicate that I have verified their correctness.
1818libNixName :: String -> String
19−libNixName "adns" = "adns"
20−libNixName "pcre" = "pcre"
21−libNixName "pq" = "postgresql"
22−libNixName "sqlite3" = "sqlite"
23−libNixName "X11" = "libX11"
24−libNixName "z" = "zlib"
25−libNixName x = x
19+libNixName "adns" = "adns"
20+libNixName "cairo" = "cairo"
21+libNixName "cairo-pdf" = "cairo"
22+libNixName "cairo-ps" = "cairo"
23+libNixName "cairo-svg" = "cairo"
24+libNixName "crypto" = "openssl"
25+libNixName "gnome-keyring" = "gnome_keyring"
26+libNixName "gnome-keyring-1" = "gnome_keyring"
27+libNixName "idn" = "idn"
28+libNixName "libidn" = "idn"
29+libNixName "libzip" = "libzip"
30+libNixName "pcre" = "pcre"
31+libNixName "pq" = "postgresql"
32+libNixName "sndfile" = "libsndfile"
33+libNixName "sqlite3" = "sqlite"
34+libNixName "xft" = "libXft"
35+libNixName "X11" = "libX11"
36+libNixName "z" = "zlib"
37+libNixName x = x
src/Cabal2Nix/Package.hs+25−12
@@ -2,8 +2,11 @@ module Cabal2Nix.Package where
22
33import Data.List
44import Data.Maybe
5+import Distribution.Compiler
56import Distribution.Package
67import Distribution.PackageDescription
8+import Distribution.PackageDescription.Configuration
9+import Distribution.System
710import Distribution.Version
811import Text.PrettyPrint
912
@@ -16,7 +19,7 @@ type PkgSHA256 = String
1619type PkgURL = String
1720type PkgDescription = String
1821type PkgLicense = License
19−type PkgDependencies = [CondTree ConfVar [Dependency] ()]
22+type PkgDependencies = [Dependency] -- [CondTree ConfVar [Dependency] ()]
2023type PkgExtraLibs = [String]
2124
2225data Pkg = Pkg PkgName
@@ -64,12 +67,9 @@ toNix (Pkg name ver sha256 url desc lic deps libs) = render doc
6467 onlyIf p d = if not (null p) then d else empty
6568 showVer = hcat (punctuate (text ".") (map int ver))
6669 pkgDeps :: [String]
67− pkgDeps = map libNixName libs ++
70+ pkgDeps = (nub $ sort $ map libNixName libs) ++
6871 (nub $ sort $ map toNixName $
69− [ n | dep <- deps,
70− Dependency (PackageName n) _ <- condTreeConstraints dep,
71− n `notElem` corePackages
72− ])
72+ filter (`notElem` corePackages) $ map unDep deps)
7373
7474-- | List of packages shipped with ghc and therefore at the moment not in
7575-- nixpkgs. This should probably be configurable at first. Later, it might
@@ -102,8 +102,8 @@ corePackages = [
102102cabal2nix :: GenericPackageDescription -> PkgSHA256 -> Pkg
103103cabal2nix cabal sha256 =
104104 Pkg pkgname pkgver sha256 url desc lic
105− (map simplify libDeps ++ map simplify exeDeps)
106− (libs ++ libs')
105+ (buildDepends tpkg)
106+ libs
107107 where
108108 pkg = packageDescription cabal
109109 PackageName pkgname = pkgName (package pkg)
@@ -112,10 +112,23 @@ cabal2nix cabal sha256 =
112112 url = homepage pkg
113113 desc = synopsis pkg
114114 -- globalDeps = buildDepends pkg
115− libDeps = maybeToList (condLibrary cabal)
116− exeDeps = [ tree | (_,tree) <- condExecutables cabal ]
117− libs = concat [ extraLibs (libBuildInfo (condTreeData x)) | x <- libDeps ]
118− libs' = concat [ extraLibs (buildInfo (condTreeData x)) | x <- exeDeps ]
115+ -- Potentially dangerous: determine a default flattening of the
116+ -- package description. Better approach: export the conditional
117+ -- structure and reflect it in the generated file.
118+ Right (tpkg, _) = finalizePackageDescription [] (const True)
119+ (Platform I386 Linux) -- shouldn't be hardcoded
120+ (CompilerId GHC (Version [7,0,4] [])) -- dito
121+ [] cabal
122+ libDeps = map libBuildInfo $ maybeToList (library tpkg)
123+ exeDeps = map buildInfo $ executables tpkg
124+ libsExtra = concatMap extraLibs (libDeps ++ exeDeps)
125+ libsPkgC = map unDep $ concatMap pkgconfigDepends (libDeps ++ exeDeps)
126+ -- add pkgconfig as an extra dependency if there are any pkgconfig deps
127+ libs = libsExtra ++ (if null libsPkgC then []
128+ else ("pkgconfig" : libsPkgC))
129+
130+unDep :: Dependency -> String
131+unDep (Dependency (PackageName x) _) = x
119132
120133simplify :: CondTree ConfVar [Dependency] a -> CondTree ConfVar [Dependency] ()
121134simplify (CondNode _ deps nodes) = CondNode () deps (map simp nodes)