@@ -2,14 +2,16 @@
22
33module Distribution.Nixpkgs.Haskell.FromCabal.PostProcess ( postProcess ) where
44
5−import Control.Lens
5+import Internal.Lens
66import Data.Maybe
7+import Data.Set ( Set )
78import qualified Data.Set as Set
89import Distribution.Nixpkgs.Haskell
910import Distribution.Package
1011import Distribution.Text
1112import Distribution.Version
12−import Language.Nix ( ) -- IsString instance for Binding
13+import Language.Nix
14+import Data.List.Split
1315
1416postProcess :: Derivation -> Derivation
1517postProcess deriv = foldr ($) (fixGtkBuilds deriv) [ f | (Dependency n vr, f) <- hooks, packageName deriv == n, packageVersion deriv `withinRange` vr ]
@@ -21,31 +23,43 @@ fixGtkBuilds drv = drv & dependencies . pkgconfig %~ (`Set.difference` buildDeps
2123
2224hooks :: [(Dependency, Derivation -> Derivation)]
2325hooks = over (mapped._1) (\str -> fromMaybe (error ("invalid constraint: " ++ show str)) (simpleParse str))
24− [ ("Agda", set (executableDepends . tool . contains "emacs") True . set phaseOverrides agdaPostInstall)
26+ [ ("Agda", set (executableDepends . tool . contains (pkg "emacs")) True . set phaseOverrides agdaPostInstall)
2527 , ("dns", set testTarget "spec") -- don't execute tests that try to access the network
26− , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList ["libXext", "libXfixes"])))
28+ , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList [pkg "libXext", pkg "libXfixes"])))
2729 , ("cabal-install", set phaseOverrides cabalInstallPostInstall)
2830 , ("darcs", set phaseOverrides darcsInstallPostInstall)
2931 , ("git-annex", gitAnnexHook)
3032 , ("haddock", set phaseOverrides "preCheck = \"unset GHC_PACKAGE_PATH\";")
3133 , ("HFuse", set phaseOverrides hfusePreConfigure)
3234 , ("gf", set phaseOverrides gfPhaseOverrides . set doCheck False)
33− , ("github-backup", set (executableDepends . tool . contains "git") True)
34− , ("GlomeVec", set (libraryDepends . pkgconfig . contains "llvm") True)
35− , ("gtk3", set (libraryDepends . pkgconfig . contains "gtk3") True) -- https://github.com/NixOS/cabal2nix/issues/145
36− , ("imagemagick", set (libraryDepends . pkgconfig . contains "imagemagick") True) -- https://github.com/NixOS/cabal2nix/issues/136
37− , ("jsaddle", set (dependencies . haskell . contains "ghcjs-base") False)
38− , ("mysql", set (libraryDepends . system . contains "mysql") True)
39− , ("pango", set (libraryDepends . haskell . contains "cairo") True)
40− , ("readline", over (libraryDepends . system) (Set.union (Set.fromList ["readline", "ncurses"])))
41− , ("terminfo", set (libraryDepends . system . contains "ncurses") True)
42− , ("thyme", set (libraryDepends . tool . contains "cpphs") True) -- required on Darwin
35+ , ("github-backup", set (executableDepends . tool . contains (pkg "git")) True)
36+ , ("GlomeVec", set (libraryDepends . pkgconfig . contains (bind "self.llvmPackages.llvm")) True)
37+ , ("gtk3", set (libraryDepends . pkgconfig . contains (pkg "gtk3")) True) -- https://github.com/NixOS/cabal2nix/issues/145
38+ , ("imagemagick", set (libraryDepends . pkgconfig . contains (pkg "imagemagick")) True) -- https://github.com/NixOS/cabal2nix/issues/136
39+ , ("jsaddle", set (dependencies . haskell . contains (pkg "ghcjs-base")) False)
40+ , ("mysql", set (libraryDepends . system . contains (pkg "mysql")) True)
41+ , ("pango", set (libraryDepends . haskell . contains (pkg "cairo")) True)
42+ , ("readline", over (libraryDepends . system) (Set.union (pkgs ["readline", "ncurses"])))
43+ , ("terminfo", set (libraryDepends . system . contains (pkg "ncurses")) True)
44+ , ("thyme", set (libraryDepends . tool . contains (pkg "cpphs")) True) -- required on Darwin
4345 , ("monad", set phaseOverrides xmonadPostInstall)
4446 , ("wxc", wxcHook)
45− , ("wxcore", set (libraryDepends . pkgconfig . contains "wxGTK") True)
46− , ("X11", over (libraryDepends . system) (Set.union (Set.fromList ["libXinerama","libXext","libXrender"])))
47+ , ("wxcore", set (libraryDepends . pkgconfig . contains (pkg "wxGTK")) True)
48+ , ("X11", over (libraryDepends . system) (Set.union (pkgs ["libXinerama","libXext","libXrender"])))
4749 ]
4850
51+pkg :: Identifier -> Binding
52+pkg i = create binding (i, create path ["pkgs",i])
53+
54+pkgs :: [Identifier] -> Set Binding
55+pkgs = Set.fromList . map pkg
56+
57+bind :: String -> Binding
58+bind s = create binding (i, create path is)
59+ where
60+ is = map (create ident) (splitOn "." s)
61+ i = last is
62+
4963gitAnnexHook :: Derivation -> Derivation
5064gitAnnexHook = set phaseOverrides gitAnnexOverrides . over (executableDepends . system) (Set.union buildInputs)
5165 where
@@ -55,7 +69,7 @@ gitAnnexHook = set phaseOverrides gitAnnexOverrides . over (executableDepends .
5569 , "installPhase = \"make PREFIX=$out CABAL=./Setup install\";"
5670 , "checkPhase = \"./git-annex test\";"
5771 ]
58− buildInputs = Set.fromList ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
72+ buildInputs = pkgs ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
5973
6074hfusePreConfigure :: String
6175hfusePreConfigure = unlines
@@ -79,8 +93,8 @@ gfPhaseOverrides = unlines
7993 ]
8094
8195wxcHook :: Derivation -> Derivation
82−wxcHook drv = drv & libraryDepends . system %~ Set.union (Set.fromList ["mesa", "libX11"])
83− & libraryDepends . pkgconfig . contains "wxGTK" .~ True
96+wxcHook drv = drv & libraryDepends . system %~ Set.union (Set.fromList [pkg "mesa", pkg "libX11"])
97+ & libraryDepends . pkgconfig . contains (pkg "wxGTK") .~ True
8498 & phaseOverrides .~ wxcPostInstall (packageVersion drv)
8599 & runHaddock .~ False
86100 where