@@ -12,72 +12,13 @@ import System.Exit
1212import Distribution.PackageDescription.Parse
1313import Distribution.PackageDescription
1414import Distribution.Package
15−import Distribution.License
1615import Data.Version
1716import Data.List
1817import Control.Monad
19−import Data.Char
2018import Network.HTTP
2119import System.Process
2220
23−type PkgName = String
24−type PkgVersion = [Int]
25−type PkgSHA256 = String
26−type PkgURL = String
27−type PkgDescription = String
28−type PkgLicense = License
29−type PkgDependencies = [CondTree ConfVar [Dependency] ()]
30−type PkgExtraLibs = [String]
31−
32−data Pkg = Pkg PkgName PkgVersion PkgSHA256 PkgURL PkgDescription PkgLicense PkgDependencies PkgExtraLibs
33− deriving (Show)
34−
35−toNixName :: String -> String
36−toNixName [] = error "toNixName: empty string is not a valid argument"
37−toNixName "Cabal" = "cabal"
38−toNixName name = f name
39− where
40− f [] = []
41− f ('-':c:cs) | c `notElem` "-" = toUpper c : f cs
42− f ('-':_) = error ("unexpected package name " ++ show name)
43− f (c:cs) = c : f cs
44−
45−toNix :: Pkg -> String
46−toNix (Pkg name ver sha256 url desc lic deps libs) =
47− "{" ++ exprArgs ++"}:\n\n"
48− ++ "cabal.mkDerivation (self : {\n"
49− ++ " pname = " ++ show name ++ ";\n"
50− ++ " version = \"" ++ showVer ++ "\";\n"
51− ++ " sha256 = " ++ show sha256 ++ ";\n"
52− ++ " propagatedBuildInputs = [" ++ depList ++ "];\n"
53− ++ " meta = {\n"
54− ++ " homepage = \"" ++ url ++ "\";\n"
55− ++ " description = " ++ show desc ++ ";\n"
56− ++ " license = " ++ showLic lic ++ ";\n"
57− ++ " };\n"
58− ++ "})\n"
59− where
60− exprArgs = concat (intersperse "," ("cabal":pkgDeps))
61− showVer = concat (intersperse "." (map show ver))
62− depList = concat (intersperse " " pkgDeps)
63− pkgDeps :: [String]
64− pkgDeps = filter (/="cabal") $ nub $ sort $ map toNixName $
65− libs ++ [ n | dep <- deps, Dependency (PackageName n) _ <- condTreeConstraints dep
66− , n `notElem` ["base","containers"]
67− ]
68− showLic (GPL Nothing) = show "GPL"
69− showLic (GPL (Just (Version [2] []))) = "self.stdenv.lib.licenses.gpl2"
70− showLic (GPL (Just (Version [3] []))) = "self.stdenv.lib.licenses.gpl3"
71− showLic (LGPL Nothing) = show "LGPL"
72− showLic (LGPL (Just (Version [2,1] []))) = "self.stdenv.lib.licenses.lgpl21"
73− showLic (LGPL (Just (Version [3] []))) = "self.stdenv.lib.licenses.lgpl3"
74− showLic BSD3 = "self.stdenv.lib.licenses.bsd3"
75− showLic BSD4 = "self.stdenv.lib.licenses.bsd4"
76− showLic MIT = "self.stdenv.lib.licenses.mit"
77− showLic PublicDomain = "self.stdenv.lib.licenses.publicDomain"
78− showLic AllRightsReserved = "unknown"
79− showLic OtherLicense = "unknown"
80− showLic l = error $ "unknown license: " ++ show l
21+import Cabal2Nix.Package
8122
8223cabal2nix :: GenericPackageDescription -> PkgSHA256 -> Pkg
8324cabal2nix cabal sha256 = Pkg pkgname pkgver sha256 url desc lic (map simplify libDeps ++ map simplify exeDeps) (libs++libs')