git.iko.soy/typeable/cabal2nix
on master help sign in
Cabal2Nix/Package.hs: some code re-factoring, no functional change
commit9646e58ffbf01eed5f13883d02376ffa559a68c7 authorPeter Simons <simons@cryp.to> dateMon 15 Aug 2011, 00:37 (15 years ago) parent064c627
1 file changed+22−18
src/Cabal2Nix/Package.hs+22−18
src/Cabal2Nix/Package.hs+22−18
@@ -11,6 +11,7 @@ import Distribution.NixOS.Derivation.Cabal
1111import Cabal2Nix.Name
1212import Cabal2Nix.CorePackages
1313import Data.List
14+-- import Data.Char
1415
1516cabal2nix :: Cabal.GenericPackageDescription -> Derivation
1617cabal2nix cabal = MkDerivation
@@ -19,10 +20,10 @@ cabal2nix cabal = MkDerivation
1920 , sha256 = "cabal2nix left the she256 field undefined"
2021 , isLibrary = isJust (Cabal.library tpkg)
2122 , isExecutable = not (null (Cabal.executables tpkg))
22− , buildDepends = pkgDeps
23− , buildTools = pkgBuildTools
24− , extraLibs = pkgLibs
25− , pkgConfDeps = pkgPCs
23+ , buildDepends = normalizeNixNames (filter (`notElem` (name : corePackages)) $ map unDep deps)
24+ , buildTools = normalizeNixNames (filter (`notElem` coreBuildTools) $ map unDep tools)
25+ , extraLibs = normalizeNixLibs libs
26+ , pkgConfDeps = normalizeNixLibs pcs
2627 , runHaddock = True
2728 , metaSection = Meta
2829 { homepage = Cabal.homepage descr
@@ -36,22 +37,16 @@ cabal2nix cabal = MkDerivation
3637 descr = Cabal.packageDescription cabal
3738 pkg = Cabal.package descr
3839 Cabal.PackageName name = Cabal.pkgName pkg
39− deps = (Cabal.buildDepends tpkg)
40− libDeps = map Cabal.libBuildInfo $ maybeToList (Cabal.library tpkg)
41− exeDeps = map Cabal.buildInfo $ Cabal.executables tpkg
42− tools = concatMap Cabal.buildTools (libDeps ++ exeDeps)
43− libs = concatMap Cabal.extraLibs (libDeps ++ exeDeps)
44− pcs = map unDep $ concatMap Cabal.pkgconfigDepends (libDeps ++ exeDeps)
40+ deps = Cabal.buildDepends tpkg
41+ libDeps = map Cabal.libBuildInfo (maybeToList (Cabal.library tpkg))
42+ exeDeps = map Cabal.buildInfo (Cabal.executables tpkg)
43+ tools = concatMap Cabal.buildTools (libDeps ++ exeDeps)
44+ libs = concatMap Cabal.extraLibs (libDeps ++ exeDeps)
45+ pcs = map unDep (concatMap Cabal.pkgconfigDepends (libDeps ++ exeDeps))
4546 Right (tpkg, _) = finalizePackageDescription [] (const True)
46− (Platform I386 Linux) -- shouldn't be hardcoded
47− (CompilerId GHC (Version [7,0,4] [])) -- dito
47+ (Platform I386 Linux) -- shouldn't be hardcoded
48+ (CompilerId GHC (Version [7,0,4] [])) -- dito
4849 [] cabal
49− pkgLibs = nub $ sort $ concatMap libNixName libs
50− pkgPCs = nub $ sort $ concatMap libNixName pcs
51− pkgDeps = nub $ sort $ map toNixName $
52− filter (`notElem` (name : corePackages)) $ map unDep deps
53− pkgBuildTools = nub $ sort $ map toNixName $
54− filter (`notElem` coreBuildTools) $ map unDep tools
5550
5651unDep :: Cabal.Dependency -> String
5752unDep (Cabal.Dependency (Cabal.PackageName x) _) = x
@@ -65,3 +60,12 @@ normalizeDescription desc
6560quote :: Char -> [Char]
6661quote '"' = "\\\""
6762quote c = [c]
63+
64+normalizeList :: [String] -> [String]
65+normalizeList = nub . sort {- By (\x y -> compare (map toLower x) (map toLower y)) -}
66+
67+normalizeNixNames :: [String] -> [String]
68+normalizeNixNames = normalizeList . map toNixName
69+
70+normalizeNixLibs :: [String] -> [String]
71+normalizeNixLibs = normalizeList . concatMap libNixName