@@ -5,6 +5,7 @@ import Data.Maybe
55import Distribution.Package
66import Distribution.PackageDescription
77import Distribution.Version
8+import Text.PrettyPrint
89
910import Cabal2Nix.License
1011import Cabal2Nix.Name
@@ -29,28 +30,42 @@ data Pkg = Pkg PkgName
2930 deriving (Show)
3031
3132toNix :: Pkg -> String
32−toNix (Pkg name ver sha256 url desc lic deps libs) =
33− "{" ++ exprArgs ++"}:\n\n"
34− ++ "cabal.mkDerivation (self : {\n"
35− ++ " pname = " ++ show name ++ ";\n"
36− ++ " version = \"" ++ showVer ++ "\";\n"
37− ++ " sha256 = " ++ show sha256 ++ ";\n"
38− ++ " propagatedBuildInputs = [" ++ depList ++ "];\n"
39− ++ " meta = {\n"
40− ++ " homepage = \"" ++ url ++ "\";\n"
41− ++ " description = " ++ show desc ++ ";\n"
42− ++ " license = " ++ showLic lic ++ ";\n"
43− ++ " };\n"
44− ++ "})\n"
33+toNix (Pkg name ver sha256 url desc lic deps libs) = render doc
4534 where
46− exprArgs = concat (intersperse "," ("cabal":pkgDeps))
47− showVer = concat (intersperse "." (map show ver))
48− depList = concat (intersperse " " pkgDeps)
35+ doc = braces (fsep $ punctuate comma $ map text ("cabal" : pkgDeps)) <+>
36+ colon $$ text "" $$
37+ vcat [
38+ text "cabal.mkDerivation" <+> lparen <> text "self" <+>
39+ colon <+> lbrace,
40+ nest 2 $ vcat [
41+ attr "pname" $ doubleQuotes (text name),
42+ attr "version" $ showVer,
43+ attr "sha256" $ doubleQuotes (text sha256),
44+ sep [
45+ text "propagatedBuildInputs" <+> equals <+> lbrack,
46+ nest 2 $ fsep $ map text pkgDeps,
47+ rbrack <> semi
48+ ],
49+ vcat [
50+ text "meta" <+> equals <+> lbrace,
51+ nest 2 $ vcat [
52+ attr "homepage" $ doubleQuotes (text url),
53+ attr "description" $ doubleQuotes (text desc),
54+ attr "license" $ text (showLic lic)
55+ ],
56+ rbrace <> semi
57+ ]
58+ ],
59+ rbrace <> rparen
60+ ]
61+ attr n v = text n <+> equals <+> v <> semi
62+ showVer = hcat (punctuate (text ".") (map int ver))
4963 pkgDeps :: [String]
50− pkgDeps = filter (/="cabal") $ nub $ sort $ map toNixName $
51− libs ++ [ n | dep <- deps, Dependency (PackageName n) _ <- condTreeConstraints dep
52− , n `notElem` corePackages
53− ]
64+ pkgDeps = nub $ sort $ map toNixName $
65+ libs ++ [ n | dep <- deps,
66+ Dependency (PackageName n) _ <- condTreeConstraints dep,
67+ n `notElem` corePackages
68+ ]
5469
5570-- | List of packages shipped with ghc and therefore at the moment not in
5671-- nixpkgs. This should probably be configurable at first. Later, it might