@@ -1,17 +1,113 @@
1−{-# LANGUAGE RecordWildCards #-}
2−
31module Cabal2Nix.PostProcess ( postProcess ) where
42
3+import Control.Lens
4+import Data.Maybe
55import qualified Data.Set as Set
66import Distribution.Nixpkgs.Haskell
7−import Distribution.Text ( display )
7+import Distribution.Package
8+import Distribution.Text
9+import Distribution.Version
810
911postProcess :: Derivation -> Derivation
10−postProcess = postProcess' . fixGtkBuilds
12+postProcess deriv = foldr ($) (fixGtkBuilds deriv) [ f | (Dependency n vr, f) <- hooks, packageName deriv == n, packageVersion deriv `withinRange` vr ]
1113
1214fixGtkBuilds :: Derivation -> Derivation
13−fixGtkBuilds deriv@(MkDerivation {..}) = deriv { pkgConfDeps = pkgConfDeps `Set.difference` buildDepends }
15+fixGtkBuilds drv = drv & dependencies . pkgconfig %~ (`Set.difference` buildDeps)
16+ where
17+ buildDeps = drv ^. dependencies . haskell
18+
19+hooks :: [(Dependency, Derivation -> Derivation)]
20+hooks = over (mapped._1) (\str -> fromMaybe (error ("invalid constraint: " ++ show str)) (simpleParse str))
21+ [ ("dns", set testTarget "spec") -- don't execute tests that try to access the network
22+ , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList [dep "libXext", dep "libXfixes"])))
23+ , ("cabal-install", set phaseOverrides cabalInstallPostInstall)
24+ , ("darcs", set phaseOverrides darcsInstallPostInstall)
25+ , ("git-annex", gitAnnexHook)
26+ , ("haddock", set phaseOverrides "preCheck = \"unset GHC_PACKAGE_PATH\";")
27+ , ("HFuse", set phaseOverrides hfusePreConfigure)
28+ , ("gf", set phaseOverrides gfPhaseOverrides . set doCheck False)
29+ , ("GlomeVec", set (libraryDepends . pkgconfig . contains (dep "llvm")) True)
30+ , ("gtk3", set (libraryDepends . pkgconfig . contains (dep "gtk3")) True)
31+ , ("jsaddle", set (dependencies . haskell . contains (dep "ghcjs-base")) False)
32+ , ("pango", set (libraryDepends . haskell . contains (dep "cairo")) True)
33+ , ("readline", over (libraryDepends . system) (Set.union (Set.fromList [dep "readline", dep "ncurses"])))
34+ , ("monad", set phaseOverrides xmonadPostInstall)
35+ , ("wxc", wxcHook)
36+ ]
37+
38+dep :: String -> Dependency
39+dep s = Dependency (PackageName s) anyVersion
40+
41+gitAnnexHook :: Derivation -> Derivation
42+gitAnnexHook = set phaseOverrides gitAnnexOverrides . over (executableDepends . system) (Set.union buildInputs)
43+ where
44+ gitAnnexOverrides = unlines
45+ [ "preConfigure = \"export HOME=$TEMPDIR\";"
46+ , "checkPhase = ''"
47+ , " cp dist/build/git-annex/git-annex git-annex"
48+ , " ./git-annex test"
49+ , "'';"
50+ ]
51+ buildInputs = Set.map dep $ Set.fromList ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
52+
53+hfusePreConfigure :: String
54+hfusePreConfigure = unlines
55+ [ "preConfigure = ''"
56+ , " sed -i -e \"s@ Extra-Lib-Dirs: /usr/local/lib@ Extra-Lib-Dirs: ${fuse}/lib@\" HFuse.cabal"
57+ , "'';"
58+ ]
59+
60+gfPhaseOverrides :: String
61+gfPhaseOverrides = unlines
62+ [ "postPatch = ''"
63+ , " sed -i \"s|\\\"-s\\\"|\\\"\\\"|\" ./Setup.hs"
64+ -- Disable silent compilation. Compiling takes long, it is best to see some
65+ -- output, otherwise it looks like the build step has stalled.
66+ , " sed -i \"s|numJobs (bf bi)++||\" ./Setup.hs"
67+ -- Parallel compilation fails. Disable it.
68+ , "'';"
69+ , "preBuild = ''export LD_LIBRARY_PATH=`pwd`/dist/build:$LD_LIBRARY_PATH'';"
70+ -- The build step itself, after having built the library, needs to be able
71+ -- to find the library it just built in order to compile grammar files.
72+ ]
73+
74+wxcHook :: Derivation -> Derivation
75+wxcHook drv = drv & libraryDepends . system %~ Set.union (Set.fromList [dep "wxGTK", dep "mesa", dep "libX11"])
76+ & phaseOverrides .~ wxcPostInstall (packageVersion drv)
77+ where
78+ wxcPostInstall :: Version -> String
79+ wxcPostInstall version = unlines
80+ [ "postInstall = ''"
81+ , " cp -v dist/build/libwxc.so." ++ display version ++ " $out/lib/libwxc.so"
82+ , "'';"
83+ ]
84+
85+cabalInstallPostInstall :: String
86+cabalInstallPostInstall = unlines
87+ [ "postInstall = ''"
88+ , " mkdir $out/etc"
89+ , " mv bash-completion $out/etc/bash_completion.d"
90+ , "'';"
91+ ]
92+
93+darcsInstallPostInstall :: String
94+darcsInstallPostInstall = unlines
95+ [ "postInstall = ''"
96+ , " mkdir -p $out/etc/bash_completion.d"
97+ , " mv contrib/darcs_completion $out/etc/bash_completion.d/darcs"
98+ , "'';"
99+ ]
100+
101+xmonadPostInstall :: String
102+xmonadPostInstall = unlines
103+ [ "postInstall = ''"
104+ , " shopt -s globstar"
105+ , " mkdir -p $out/share/man/man1"
106+ , " mv \"$out/\"**\"/man/\"*.1 $out/share/man/man1/"
107+ , "'';"
108+ ]
14109
110+{-
15111postProcess' :: Derivation -> Derivation
16112postProcess' deriv@(MkDerivation {..})
17113 | pname == "aeson" && version > Version [0,7] []
@@ -22,16 +118,11 @@ postProcess' deriv@(MkDerivation {..})
22118 | pname == "alex" && version >= Version [3,1] []
23119 = deriv { buildTools = Set.insert "perl" (Set.insert "happy" buildTools) }
24120 | pname == "apache-md5" = deriv { testDepends = Set.delete "crypto" testDepends }
25− | pname == "bindings-GLFW" = deriv { extraLibs = Set.insert "libXext" (Set.insert "libXfixes" extraLibs) }
26121 | pname == "bits-extras" = deriv { configureFlags = Set.insert "--ghc-option=-lgcc_s" configureFlags
27122 , extraLibs = Set.filter (/= "gcc_s") extraLibs
28123 }
29124 | pname == "Cabal" = deriv { phaseOverrides = "preCheck = \"unset GHC_PACKAGE_PATH; export HOME=$NIX_BUILD_TOP\";" }
30125 | pname == "cabal-bounds" = deriv { buildTools = Set.insert "cabal-install" buildTools }
31− | pname == "cabal-install" && version >= Version [0,14] []
32− = deriv { phaseOverrides = cabalInstallPostInstall }
33− | pname == "darcs" = deriv { phaseOverrides = darcsInstallPostInstall }
34− | pname == "dns" = deriv { testTarget = "spec" }
35126 | pname == "editline" = deriv { extraLibs = Set.insert "libedit" extraLibs }
36127 | pname == "epic" = deriv { extraLibs = Set.insert "gmp" (Set.insert "boehmgc" extraLibs)
37128 , buildTools = Set.insert "happy" buildTools
@@ -42,8 +133,6 @@ postProcess' deriv@(MkDerivation {..})
42133 , phaseOverrides = ghcParserPatchPhase }
43134 | pname == "ghc-paths" = deriv { phaseOverrides = ghcPathsPatches }
44135 | pname == "ghc-vis" = deriv { phaseOverrides = ghciPostInstall }
45− | pname == "git-annex" = deriv { phaseOverrides = gitAnnexOverrides
46− , buildTools = Set.fromList ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"] `Set.union` buildTools }
47136 | pname == "github-backup" = deriv { buildTools = Set.insert "git" buildTools }
48137 | pname == "gloss-raster" = deriv { extraLibs = Set.insert "llvm" extraLibs }
49138 | pname == "GLUT" = deriv { extraLibs = Set.fromList ["glut","libSM","libICE","libXmu","libXi","mesa"] `Set.union` extraLibs }
@@ -51,15 +140,10 @@ postProcess' deriv@(MkDerivation {..})
51140 | pname == "gtk2hs-buildtools"= deriv { buildDepends = Set.insert "hashtables" buildDepends }
52141 | pname == "haddock" && version < Version [2,14] []
53142 = deriv { buildTools = Set.insert "alex" (Set.insert "happy" buildTools) }
54− | pname == "gf" = deriv { phaseOverrides = gfPhaseOverrides
55− , doCheck = False }
56− | pname == "GlomeVec" = deriv { buildTools = Set.insert "llvm" buildTools }
57− | pname == "haddock" = deriv { phaseOverrides = haddockPreCheck }
58143 | pname == "happy" = deriv { buildTools = Set.insert "perl" buildTools }
59144 | pname == "haskeline" = deriv { buildDepends = Set.insert "utf8-string" buildDepends }
60145 | pname == "haskell-src" = deriv { buildTools = Set.insert "happy" buildTools }
61146 | pname == "haskell-src-meta" = deriv { buildDepends = Set.insert "uniplate" buildDepends }
62− | pname == "HFuse" = deriv { phaseOverrides = hfusePreConfigure }
63147 | pname == "hlibgit2" = deriv { buildTools = Set.insert "git" buildTools }
64148 | pname == "HList" = deriv { buildTools = Set.insert "diffutils" buildTools }
65149 | pname == "hmatrix" = deriv { extraLibs = Set.insert "liblapack" (Set.insert "blas" (Set.filter (/= "lapack") extraLibs)) }
@@ -87,7 +171,6 @@ postProcess' deriv@(MkDerivation {..})
87171 | pname == "pcap" = deriv { extraLibs = Set.insert "libpcap" extraLibs }
88172 | pname == "persistent" = deriv { extraLibs = Set.insert "sqlite3" extraLibs }
89173 | pname == "purescript" = deriv { buildTools = Set.insert "nodejs" buildTools }
90− | pname == "readline" = deriv { extraLibs = Set.insert "readline" (Set.insert "ncurses" extraLibs) }
91174 | pname == "repa-algorithms" = deriv { extraLibs = Set.insert "llvm" extraLibs }
92175 | pname == "repa-examples" = deriv { extraLibs = Set.insert "llvm" extraLibs }
93176 | pname == "saltine" = deriv { extraLibs = Set.map (\x -> if x == "sodium" then "libsodium" else x) extraLibs }
@@ -103,9 +186,6 @@ postProcess' deriv@(MkDerivation {..})
103186 | pname == "threadscope" = deriv { configureFlags = Set.insert "--ghc-options=-rtsopts" configureFlags }
104187 | pname == "thyme" = deriv { buildTools = Set.insert "cpphs" buildTools }
105188 | pname == "vacuum" = deriv { extraLibs = Set.insert "ghc-paths" extraLibs }
106− | pname == "wxc" = deriv { extraLibs = Set.fromList ["wxGTK","mesa","libX11"] `Set.union` extraLibs
107− , phaseOverrides = wxcPostInstall version
108− }
109189 | pname == "wxcore" = deriv { extraLibs = Set.fromList ["wxGTK","mesa","libX11"] `Set.union` extraLibs }
110190 | pname == "X11" && version >= Version [1,6] []
111191 = deriv { extraLibs = Set.fromList ["libXinerama","libXext","libXrender"] `Set.union` extraLibs }
@@ -119,7 +199,6 @@ postProcess' deriv@(MkDerivation {..})
119199
120200 | pname == "hnetcdf" = deriv { testDepends = Set.delete "netcdf" testDepends }
121201 | pname == "SDL2-ttf" = deriv { buildDepends = Set.delete "SDL2" buildDepends }
122− | pname == "jsaddle" = deriv { buildDepends = Set.delete "ghcjs-base" buildDepends, testDepends = Set.delete "ghcjs-base" testDepends }
123202 | pname == "hzk" = deriv { testDepends = Set.delete "zookeeper_mt" testDepends, buildTools = Set.insert "zookeeper_mt" buildTools }
124203 | pname == "z3" = deriv { phaseOverrides = "preBuild = stdenv.lib.optionalString stdenv.isDarwin \"export DYLD_LIBRARY_PATH=${z3}/lib\";" }
125204 | pname == "zip-archive" = deriv { testDepends = Set.delete "zip" testDepends, buildTools = Set.insert "zip" buildTools }
@@ -138,47 +217,6 @@ ghcModPostInstall pname version = unlines
138217 , "'';"
139218 ]
140219
141−wxcPostInstall :: Version -> String
142−wxcPostInstall version = unlines
143− [ "postInstall = ''"
144− , " cp -v dist/build/libwxc.so." ++ display version ++ " $out/lib/libwxc.so"
145− , "'';"
146− ]
147−
148−cabalInstallPostInstall :: String
149−cabalInstallPostInstall = unlines
150− [ "postInstall = ''"
151− , " mkdir $out/etc"
152− , " mv bash-completion $out/etc/bash_completion.d"
153− , "'';"
154− ]
155−
156−darcsInstallPostInstall :: String
157−darcsInstallPostInstall = unlines
158− [ "postInstall = ''"
159− , " mkdir -p $out/etc/bash_completion.d"
160− , " mv contrib/darcs_completion $out/etc/bash_completion.d/darcs"
161− , "'';"
162− ]
163−
164−xmonadPostInstall :: String
165−xmonadPostInstall = unlines
166− [ "postInstall = ''"
167− , " shopt -s globstar"
168− , " mkdir -p $out/share/man/man1"
169− , " mv \"$out/\"**\"/man/\"*.1 $out/share/man/man1/"
170− , "'';"
171− ]
172−
173−gitAnnexOverrides :: String
174−gitAnnexOverrides = unlines
175− [ "preConfigure = \"export HOME=$TEMPDIR\";"
176− , "checkPhase = ''"
177− , " cp dist/build/git-annex/git-annex git-annex"
178− , " ./git-annex test"
179− , "'';"
180− ]
181−
182220ghciPostInstall :: String
183221ghciPostInstall = unlines
184222 [ "postInstall = ''"
@@ -187,12 +225,6 @@ ghciPostInstall = unlines
187225 , "'';"
188226 ]
189227
190−hfusePreConfigure :: String
191−hfusePreConfigure = unlines
192− [ "preConfigure = ''"
193− , " sed -i -e \"s@ Extra-Lib-Dirs: /usr/local/lib@ Extra-Lib-Dirs: ${fuse}/lib@\" HFuse.cabal"
194− , "'';"
195− ]
196228
197229ghcPathsPatches :: String
198230ghcPathsPatches = "patches = [ ./ghc-paths-nix.patch ];"
@@ -244,16 +276,4 @@ ghcParserPatchPhase = unlines
244276 , "'';"
245277 ]
246278
247−gfPhaseOverrides :: String
248−gfPhaseOverrides = unlines
249− [ "postPatch = ''"
250− , " sed -i \"s|\\\"-s\\\"|\\\"\\\"|\" ./Setup.hs"
251− -- Disable silent compilation. Compiling takes long, it is best to see some
252− -- output, otherwise it looks like the build step has stalled.
253− , " sed -i \"s|numJobs (bf bi)++||\" ./Setup.hs"
254− -- Parallel compilation fails. Disable it.
255− , "'';"
256− , "preBuild = ''export LD_LIBRARY_PATH=`pwd`/dist/build:$LD_LIBRARY_PATH'';"
257− -- The build step itself, after having built the library, needs to be able
258− -- to find the library it just built in order to compile grammar files.
259− ]
279+-}