git.iko.soy/typeable/cabal2nix
on master help sign in
Remove the name mangling logic that maps Haskell package names to Nix

attributes. We support names with dashes in them for quite a while now, so the mangling isn't necessary any more.

commit5f97ba5359bad2ef57d5920b4b335c962d6d3553 authorPeter Simons <simons@cryp.to> dateSun 14 Dec 2014, 15:43 (12 years ago) parent372de78
5 files changed+39−34
src/Cabal2Nix/Name.hs+11−7 src/Distribution/NixOS/Derivation/Cabal.hs+6−6 src/Distribution/NixOS/Derivation/Meta.hs+8−12 src/Distribution/NixOS/PrettyPrinting.hs+3−3 src/hackage2nix.hs+11−6
src/Cabal2Nix/Name.hs+11−7
@@ -1,11 +1,15 @@
1−module Cabal2Nix.Name ( toNixName, libNixName, buildToolNixName ) where
1+module Cabal2Nix.Name ( toNixName, toNixName', libNixName, buildToolNixName ) where
22
33import Data.Char
44
55-- | Map Cabal names to Nix attribute names.
66toNixName :: String -> String
7−toNixName [] = error "toNixName: empty string is not a valid argument"
8−toNixName name = f name
7+toNixName = id
8+
9+-- | The old mapping function. This may be useful to generate a compatibility layer.
10+toNixName' :: String -> String
11+toNixName' [] = error "toNixName: empty string is not a valid argument"
12+toNixName' name = f name
913 where
1014 f [] = []
1115 f ('-':c:cs) | c `notElem` "-" = toUpper c : f cs
@@ -124,8 +128,8 @@ libNixName x = return x
124128
125129-- | Map build tool names to Nix attribute names.
126130buildToolNixName :: String -> [String]
127−buildToolNixName "cabal" = return "cabalInstall"
128−buildToolNixName "gtk2hsC2hs" = return "gtk2hsBuildtools"
129−buildToolNixName "gtk2hsHookGenerator" = return "gtk2hsBuildtools"
130−buildToolNixName "gtk2hsTypeGen" = return "gtk2hsBuildtools"
131+buildToolNixName "cabal" = return "cabal-install"
132+buildToolNixName "gtk2hsC2hs" = return "gtk2hs-buildtools"
133+buildToolNixName "gtk2hsHookGenerator" = return "gtk2hs-buildtools"
134+buildToolNixName "gtk2hsTypeGen" = return "gtk2hs-buildtools"
131135buildToolNixName x = return (toNixName x)
src/Distribution/NixOS/Derivation/Cabal.hs+6−6
@@ -87,8 +87,8 @@ deepseqFlagAssignment ((FlagName n, v):as) b = n `deepseq` v `deepseq` as `deeps
8787
8888renderDerivation :: Derivation -> Doc
8989renderDerivation deriv =
90− funargs (map text ("buildCabal":inputs)) $$ vcat
91− [ text "buildCabal" <+> lbrace
90+ funargs (map text ("mkDerivation":inputs)) $$ vcat
91+ [ text "mkDerivation" <+> lbrace
9292 , nest 2 $ vcat
9393 [ attr "pname" $ string (pname deriv)
9494 , attr "version" $ doubleQuotes (disp (version deriv))
@@ -100,20 +100,20 @@ renderDerivation deriv =
100100 , listattr "buildTools" empty (buildTools deriv)
101101 , listattr "extraLibraries" empty (extraLibs deriv)
102102 , listattr "pkgconfigDepends" empty (pkgConfDeps deriv)
103− , onlyIf renderedFlags $ attr "configureFlags" $ doubleQuotes (sep renderedFlags)
103+ , onlyIf (not (null renderedFlags)) $ attr "configureFlags" $ doubleQuotes (sep renderedFlags)
104104 , boolattr "enableSplitObjs" (not (enableSplitObjs deriv)) (enableSplitObjs deriv)
105105 , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv))
106106 , boolattr "jailbreak" (jailbreak deriv) (jailbreak deriv)
107107 , boolattr "doCheck" (not (doCheck deriv)) (doCheck deriv)
108− , onlyIf (testTarget deriv) $ attr "testTarget" $ string (testTarget deriv)
108+ , onlyIf (not (null (testTarget deriv))) $ attr "testTarget" $ string (testTarget deriv)
109109 , boolattr "hyperlinkSource" (not (hyperlinkSource deriv)) (hyperlinkSource deriv)
110− , onlyIf (phaseOverrides deriv) $ vcat ((map text . lines) (phaseOverrides deriv))
110+ , onlyIf (not (null (phaseOverrides deriv))) $ vcat ((map text . lines) (phaseOverrides deriv))
111111 , disp (metaSection deriv)
112112 ]
113113 , rbrace
114114 ]
115115 where
116− inputs = nub $ sortBy (compare `on` map toLower) $ filter (/="cabal") $ filter (not . isPrefixOf "stdenv.") $
116+ inputs = nub $ sortBy (compare `on` map toLower) $ filter (not . isPrefixOf "stdenv.") $
117117 buildDepends deriv ++ testDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv ++ extraFunctionArgs deriv
118118 ++ ["fetch" ++ derivKind (src deriv) | derivKind (src deriv) /= "" && not isHackagePackage]
119119 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
src/Distribution/NixOS/Derivation/Meta.hs+8−12
@@ -61,18 +61,14 @@ instance NFData Meta where
6161
6262renderMeta :: Meta -> Doc
6363renderMeta meta = vcat
64− [ text "meta" <+> equals <+> lbrace
65− , nest 2 $ vcat
66− [ onlyIf (homepage meta) $ attr "homepage" $ string (homepage meta)
67− , onlyIf (description meta) $ attr "description" $ string (description meta)
68− , attr "license" $ disp (license meta)
69− , onlyIf (platforms meta) $ sep
70− [ text "platforms" <+> equals, renderPlatformList (platforms meta) ]
71− , onlyIf (hydraPlatforms meta) $ sep
72− [ text "hydraPlatforms" <+> equals, renderPlatformList (hydraPlatforms meta) ]
73− , listattr "maintainers" (text "with self.stdenv.lib.maintainers;") (maintainers meta)
74− ]
75− , rbrace <> semi
64+ [ onlyIf (not (null (homepage meta))) $ attr "homepage" $ string (homepage meta)
65+ , onlyIf (not (null (description meta))) $ attr "description" $ string (description meta)
66+ , attr "license" $ disp (license meta)
67+ , onlyIf (not (null (platforms meta)) && platforms meta /= ["ghc.meta.platforms"]) $ sep
68+ [ text "platforms" <+> equals, renderPlatformList (platforms meta) ]
69+ , onlyIf (not (null (hydraPlatforms meta))) $ sep
70+ [ text "hydraPlatforms" <+> equals, renderPlatformList (hydraPlatforms meta) ]
71+ , listattr "maintainers" (text "with self.stdenv.lib.maintainers;") (maintainers meta)
7672 ]
7773
7874renderPlatformList :: [String] -> Doc
src/Distribution/NixOS/PrettyPrinting.hs+3−3
@@ -25,14 +25,14 @@ import Text.PrettyPrint
2525attr :: String -> Doc -> Doc
2626attr n v = text n <+> equals <+> v <> semi
2727
28−onlyIf :: [a] -> Doc -> Doc
29−onlyIf p d = if not (null p) then d else empty
28+onlyIf :: Bool -> Doc -> Doc
29+onlyIf b d = if b then d else empty
3030
3131boolattr :: String -> Bool -> Bool -> Doc
3232boolattr n p v = if p then attr n (bool v) else empty
3333
3434listattr :: String -> Doc -> [String] -> Doc
35−listattr n prefix vs = onlyIf vs $
35+listattr n prefix vs = onlyIf (not (null vs)) $
3636 sep [ text n <+> equals <+> prefix <+> lbrack,
3737 nest 2 $ fsep $ map text vs,
3838 rbrack <> semi
src/hackage2nix.hs+11−6
@@ -22,19 +22,24 @@ main :: IO ()
2222main = readHackage >>= runParIO . generatePackageSet
2323
2424nixAttr :: String -> Version -> String
25−nixAttr name _ = show $ toNixName name -- ++ "_" ++ [ if c == '.' then '_' else c | c <- display ver ]
25+nixAttr name ver = name -- ++ "_" ++ [ if c == '.' then '_' else c | c <- display ver ]
2626
2727generatePackageSet :: Hackage -> ParIO ()
28−generatePackageSet db' = do
29− let db = foldr Map.delete db' ["smtLib", "testPkg"]
28+generatePackageSet db = do
3029 pkgs <- parMapM generatePackage (Map.toList db)
3130 liftIO $ putStrLn "/* hackage-packages.nix is an auto-generated file -- DO NOT EDIT! */"
3231 liftIO $ putStrLn ""
33− liftIO $ putStrLn "{ stdenv, ghc, pkgs, definePackage }:"
32+ liftIO $ putStrLn "{ pkgs, stdenv, callPackage }:"
33+ liftIO $ putStrLn ""
34+ liftIO $ putStrLn "self: {"
3435 liftIO $ putStrLn ""
35− liftIO $ putStrLn "{"
3636 forM_ pkgs $ \(name, version, nixExpr) -> do
37− liftIO $ print $ nest 2 $ hang (text (nixAttr name version) <+> equals <+> text "definePackage {}") 2 (parens (disp nixExpr)) <> semi
37+ -- when (name /= toNixName' name) $
38+ -- liftIO $ print $ nest 2 $ (string (toNixName' name) <+> equals <+> text ("self." ++ show (nixAttr name version))) <> semi
39+ -- liftIO $ print $ nest 2 $ (string (toNixName' name) <+> equals <+> text ("self." ++ show (nixAttr name version))) <> semi
40+ -- when (name /= toNixName' name) $
41+ -- liftIO $ print $ nest 2 $ (string name <+> equals <+> text ("self." ++ show (nixAttr name version))) <> semi
42+ liftIO $ print $ nest 2 $ hang (string (nixAttr name version) <+> equals <+> text "callPackage") 2 (parens (disp nixExpr)) <+> (text "{}" <> semi)
3843 liftIO $ putStrLn ""
3944 liftIO $ putStrLn "}"
4045