@@ -1,17 +1,113 @@
1−{-# LANGUAGE RecordWildCards #-}
3module Cabal2Nix.PostProcess ( postProcess ) where
1module Cabal2Nix.PostProcess ( postProcess ) where
5import qualified Data.Set as Set
5import qualified Data.Set as Set
6import Distribution.Nixpkgs.Haskell
6import Distribution.Nixpkgs.Haskell
7−import Distribution.Text ( display )
7+import Distribution.Package
8+import Distribution.Text
9+import Distribution.Version
9postProcess :: Derivation -> Derivation
11postProcess :: 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 ]
12fixGtkBuilds :: Derivation -> Derivation
14fixGtkBuilds :: Derivation -> Derivation
13−fixGtkBuilds deriv@(MkDerivation {..}) = deriv { pkgConfDeps = pkgConfDeps `Set.difference` buildDepends }
15+fixGtkBuilds drv = drv & dependencies . pkgconfig %~ (`Set.difference` buildDeps)
17+ buildDeps = drv ^. dependencies . haskell
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)
38+dep :: String -> Dependency
39+dep s = Dependency (PackageName s) anyVersion
41+gitAnnexHook :: Derivation -> Derivation
42+gitAnnexHook = set phaseOverrides gitAnnexOverrides . over (executableDepends . system) (Set.union buildInputs)
44+ gitAnnexOverrides = unlines
45+ [ "preConfigure = \"export HOME=$TEMPDIR\";"
47+ , " cp dist/build/git-annex/git-annex git-annex"
48+ , " ./git-annex test"
51+ buildInputs = Set.map dep $ Set.fromList ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
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"
60+gfPhaseOverrides :: String
61+gfPhaseOverrides = unlines
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.
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.
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)
78+ wxcPostInstall :: Version -> String
79+ wxcPostInstall version = unlines
81+ , " cp -v dist/build/libwxc.so." ++ display version ++ " $out/lib/libwxc.so"
85+cabalInstallPostInstall :: String
86+cabalInstallPostInstall = unlines
89+ , " mv bash-completion $out/etc/bash_completion.d"
93+darcsInstallPostInstall :: String
94+darcsInstallPostInstall = unlines
96+ , " mkdir -p $out/etc/bash_completion.d"
97+ , " mv contrib/darcs_completion $out/etc/bash_completion.d/darcs"
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/"
15postProcess' :: Derivation -> Derivation
111postProcess' :: Derivation -> Derivation
16postProcess' deriv@(MkDerivation {..})
112postProcess' deriv@(MkDerivation {..})
17 | pname == "aeson" && version > Version [0,7] []
113 | pname == "aeson" && version > Version [0,7] []
@@ -22,16 +118,11 @@ postProcess' deriv@(MkDerivation {..})
22 | pname == "alex" && version >= Version [3,1] []
118 | pname == "alex" && version >= Version [3,1] []
23 = deriv { buildTools = Set.insert "perl" (Set.insert "happy" buildTools) }
119 = deriv { buildTools = Set.insert "perl" (Set.insert "happy" buildTools) }
24 | pname == "apache-md5" = deriv { testDepends = Set.delete "crypto" testDepends }
120 | pname == "apache-md5" = deriv { testDepends = Set.delete "crypto" testDepends }
25− | pname == "bindings-GLFW" = deriv { extraLibs = Set.insert "libXext" (Set.insert "libXfixes" extraLibs) }
26 | pname == "bits-extras" = deriv { configureFlags = Set.insert "--ghc-option=-lgcc_s" configureFlags
121 | pname == "bits-extras" = deriv { configureFlags = Set.insert "--ghc-option=-lgcc_s" configureFlags
27 , extraLibs = Set.filter (/= "gcc_s") extraLibs
122 , extraLibs = Set.filter (/= "gcc_s") extraLibs
29 | pname == "Cabal" = deriv { phaseOverrides = "preCheck = \"unset GHC_PACKAGE_PATH; export HOME=$NIX_BUILD_TOP\";" }
124 | pname == "Cabal" = deriv { phaseOverrides = "preCheck = \"unset GHC_PACKAGE_PATH; export HOME=$NIX_BUILD_TOP\";" }
30 | pname == "cabal-bounds" = deriv { buildTools = Set.insert "cabal-install" buildTools }
125 | 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" }
35 | pname == "editline" = deriv { extraLibs = Set.insert "libedit" extraLibs }
126 | pname == "editline" = deriv { extraLibs = Set.insert "libedit" extraLibs }
36 | pname == "epic" = deriv { extraLibs = Set.insert "gmp" (Set.insert "boehmgc" extraLibs)
127 | pname == "epic" = deriv { extraLibs = Set.insert "gmp" (Set.insert "boehmgc" extraLibs)
37 , buildTools = Set.insert "happy" buildTools
128 , buildTools = Set.insert "happy" buildTools
@@ -42,8 +133,6 @@ postProcess' deriv@(MkDerivation {..})
42 , phaseOverrides = ghcParserPatchPhase }
133 , phaseOverrides = ghcParserPatchPhase }
43 | pname == "ghc-paths" = deriv { phaseOverrides = ghcPathsPatches }
134 | pname == "ghc-paths" = deriv { phaseOverrides = ghcPathsPatches }
44 | pname == "ghc-vis" = deriv { phaseOverrides = ghciPostInstall }
135 | 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 }
47 | pname == "github-backup" = deriv { buildTools = Set.insert "git" buildTools }
136 | pname == "github-backup" = deriv { buildTools = Set.insert "git" buildTools }
48 | pname == "gloss-raster" = deriv { extraLibs = Set.insert "llvm" extraLibs }
137 | pname == "gloss-raster" = deriv { extraLibs = Set.insert "llvm" extraLibs }
49 | pname == "GLUT" = deriv { extraLibs = Set.fromList ["glut","libSM","libICE","libXmu","libXi","mesa"] `Set.union` extraLibs }
138 | pname == "GLUT" = deriv { extraLibs = Set.fromList ["glut","libSM","libICE","libXmu","libXi","mesa"] `Set.union` extraLibs }
@@ -51,15 +140,10 @@ postProcess' deriv@(MkDerivation {..})
51 | pname == "gtk2hs-buildtools"= deriv { buildDepends = Set.insert "hashtables" buildDepends }
140 | pname == "gtk2hs-buildtools"= deriv { buildDepends = Set.insert "hashtables" buildDepends }
52 | pname == "haddock" && version < Version [2,14] []
141 | pname == "haddock" && version < Version [2,14] []
53 = deriv { buildTools = Set.insert "alex" (Set.insert "happy" buildTools) }
142 = deriv { buildTools = Set.insert "alex" (Set.insert "happy" buildTools) }
54− | pname == "gf" = deriv { phaseOverrides = gfPhaseOverrides
56− | pname == "GlomeVec" = deriv { buildTools = Set.insert "llvm" buildTools }
57− | pname == "haddock" = deriv { phaseOverrides = haddockPreCheck }
58 | pname == "happy" = deriv { buildTools = Set.insert "perl" buildTools }
143 | pname == "happy" = deriv { buildTools = Set.insert "perl" buildTools }
59 | pname == "haskeline" = deriv { buildDepends = Set.insert "utf8-string" buildDepends }
144 | pname == "haskeline" = deriv { buildDepends = Set.insert "utf8-string" buildDepends }
60 | pname == "haskell-src" = deriv { buildTools = Set.insert "happy" buildTools }
145 | pname == "haskell-src" = deriv { buildTools = Set.insert "happy" buildTools }
61 | pname == "haskell-src-meta" = deriv { buildDepends = Set.insert "uniplate" buildDepends }
146 | pname == "haskell-src-meta" = deriv { buildDepends = Set.insert "uniplate" buildDepends }
62− | pname == "HFuse" = deriv { phaseOverrides = hfusePreConfigure }
63 | pname == "hlibgit2" = deriv { buildTools = Set.insert "git" buildTools }
147 | pname == "hlibgit2" = deriv { buildTools = Set.insert "git" buildTools }
64 | pname == "HList" = deriv { buildTools = Set.insert "diffutils" buildTools }
148 | pname == "HList" = deriv { buildTools = Set.insert "diffutils" buildTools }
65 | pname == "hmatrix" = deriv { extraLibs = Set.insert "liblapack" (Set.insert "blas" (Set.filter (/= "lapack") extraLibs)) }
149 | pname == "hmatrix" = deriv { extraLibs = Set.insert "liblapack" (Set.insert "blas" (Set.filter (/= "lapack") extraLibs)) }
@@ -87,7 +171,6 @@ postProcess' deriv@(MkDerivation {..})
87 | pname == "pcap" = deriv { extraLibs = Set.insert "libpcap" extraLibs }
171 | pname == "pcap" = deriv { extraLibs = Set.insert "libpcap" extraLibs }
88 | pname == "persistent" = deriv { extraLibs = Set.insert "sqlite3" extraLibs }
172 | pname == "persistent" = deriv { extraLibs = Set.insert "sqlite3" extraLibs }
89 | pname == "purescript" = deriv { buildTools = Set.insert "nodejs" buildTools }
173 | pname == "purescript" = deriv { buildTools = Set.insert "nodejs" buildTools }
90− | pname == "readline" = deriv { extraLibs = Set.insert "readline" (Set.insert "ncurses" extraLibs) }
91 | pname == "repa-algorithms" = deriv { extraLibs = Set.insert "llvm" extraLibs }
174 | pname == "repa-algorithms" = deriv { extraLibs = Set.insert "llvm" extraLibs }
92 | pname == "repa-examples" = deriv { extraLibs = Set.insert "llvm" extraLibs }
175 | pname == "repa-examples" = deriv { extraLibs = Set.insert "llvm" extraLibs }
93 | pname == "saltine" = deriv { extraLibs = Set.map (\x -> if x == "sodium" then "libsodium" else x) extraLibs }
176 | pname == "saltine" = deriv { extraLibs = Set.map (\x -> if x == "sodium" then "libsodium" else x) extraLibs }
@@ -103,9 +186,6 @@ postProcess' deriv@(MkDerivation {..})
103 | pname == "threadscope" = deriv { configureFlags = Set.insert "--ghc-options=-rtsopts" configureFlags }
186 | pname == "threadscope" = deriv { configureFlags = Set.insert "--ghc-options=-rtsopts" configureFlags }
104 | pname == "thyme" = deriv { buildTools = Set.insert "cpphs" buildTools }
187 | pname == "thyme" = deriv { buildTools = Set.insert "cpphs" buildTools }
105 | pname == "vacuum" = deriv { extraLibs = Set.insert "ghc-paths" extraLibs }
188 | 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
109 | pname == "wxcore" = deriv { extraLibs = Set.fromList ["wxGTK","mesa","libX11"] `Set.union` extraLibs }
189 | pname == "wxcore" = deriv { extraLibs = Set.fromList ["wxGTK","mesa","libX11"] `Set.union` extraLibs }
110 | pname == "X11" && version >= Version [1,6] []
190 | pname == "X11" && version >= Version [1,6] []
111 = deriv { extraLibs = Set.fromList ["libXinerama","libXext","libXrender"] `Set.union` extraLibs }
191 = deriv { extraLibs = Set.fromList ["libXinerama","libXext","libXrender"] `Set.union` extraLibs }
@@ -119,7 +199,6 @@ postProcess' deriv@(MkDerivation {..})
120 | pname == "hnetcdf" = deriv { testDepends = Set.delete "netcdf" testDepends }
200 | pname == "hnetcdf" = deriv { testDepends = Set.delete "netcdf" testDepends }
121 | pname == "SDL2-ttf" = deriv { buildDepends = Set.delete "SDL2" buildDepends }
201 | 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 }
123 | pname == "hzk" = deriv { testDepends = Set.delete "zookeeper_mt" testDepends, buildTools = Set.insert "zookeeper_mt" buildTools }
202 | pname == "hzk" = deriv { testDepends = Set.delete "zookeeper_mt" testDepends, buildTools = Set.insert "zookeeper_mt" buildTools }
124 | pname == "z3" = deriv { phaseOverrides = "preBuild = stdenv.lib.optionalString stdenv.isDarwin \"export DYLD_LIBRARY_PATH=${z3}/lib\";" }
203 | pname == "z3" = deriv { phaseOverrides = "preBuild = stdenv.lib.optionalString stdenv.isDarwin \"export DYLD_LIBRARY_PATH=${z3}/lib\";" }
125 | pname == "zip-archive" = deriv { testDepends = Set.delete "zip" testDepends, buildTools = Set.insert "zip" buildTools }
204 | pname == "zip-archive" = deriv { testDepends = Set.delete "zip" testDepends, buildTools = Set.insert "zip" buildTools }
@@ -138,47 +217,6 @@ ghcModPostInstall pname version = unlines
141−wxcPostInstall :: Version -> String
142−wxcPostInstall version = unlines
143− [ "postInstall = ''"
144− , " cp -v dist/build/libwxc.so." ++ display version ++ " $out/lib/libwxc.so"
148−cabalInstallPostInstall :: String
149−cabalInstallPostInstall = unlines
150− [ "postInstall = ''"
152− , " mv bash-completion $out/etc/bash_completion.d"
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"
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/"
173−gitAnnexOverrides :: String
174−gitAnnexOverrides = unlines
175− [ "preConfigure = \"export HOME=$TEMPDIR\";"
177− , " cp dist/build/git-annex/git-annex git-annex"
178− , " ./git-annex test"
182ghciPostInstall :: String
220ghciPostInstall :: String
183ghciPostInstall = unlines
221ghciPostInstall = unlines
184 [ "postInstall = ''"
222 [ "postInstall = ''"
@@ -187,12 +225,6 @@ ghciPostInstall = unlines
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"
197ghcPathsPatches :: String
229ghcPathsPatches :: String
198ghcPathsPatches = "patches = [ ./ghc-paths-nix.patch ];"
230ghcPathsPatches = "patches = [ ./ghc-paths-nix.patch ];"
@@ -244,16 +276,4 @@ ghcParserPatchPhase = unlines
247−gfPhaseOverrides :: String
279+-}
248−gfPhaseOverrides = unlines
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.
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.