git.iko.soy/typeable/cabal2nix
on de15503 help sign in
263 lines 14 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
3module Cabal2Nix.PostProcess ( postProcess ) where
5import Control.Lens
6import Data.Maybe
7import qualified Data.Set as Set
8import Distribution.Nixpkgs.Haskell
9import Distribution.Package
10import Distribution.Text
11import Distribution.Version
13postProcess :: Derivation -> Derivation
14postProcess deriv = foldr ($) (fixGtkBuilds deriv) [ f | (Dependency n vr, f) <- hooks, packageName deriv == n, packageVersion deriv `withinRange` vr ]
16fixGtkBuilds :: Derivation -> Derivation
17fixGtkBuilds drv = drv & dependencies . pkgconfig %~ (`Set.difference` buildDeps)
18 where
19 buildDeps = drv ^. dependencies . haskell
21hooks :: [(Dependency, Derivation -> Derivation)]
22hooks = over (mapped._1) (\str -> fromMaybe (error ("invalid constraint: " ++ show str)) (simpleParse str))
23 [ ("Agda", set (executableDepends . tool . contains "emacs") True . set phaseOverrides agdaPostInstall)
24 , ("dns", set testTarget "spec") -- don't execute tests that try to access the network
25 , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList ["libXext", "libXfixes"])))
26 , ("cabal-install", set phaseOverrides cabalInstallPostInstall)
27 , ("darcs", set phaseOverrides darcsInstallPostInstall)
28 , ("git-annex", gitAnnexHook)
29 , ("haddock", set phaseOverrides "preCheck = \"unset GHC_PACKAGE_PATH\";")
30 , ("HFuse", set phaseOverrides hfusePreConfigure)
31 , ("gf", set phaseOverrides gfPhaseOverrides . set doCheck False)
32 , ("github-backup", set (executableDepends . tool . contains "git") True)
33 , ("GlomeVec", set (libraryDepends . pkgconfig . contains "llvm") True)
34 , ("gtk3", set (libraryDepends . pkgconfig . contains "gtk3") True) -- https://github.com/NixOS/cabal2nix/issues/145
35 , ("imagemagick", set (libraryDepends . pkgconfig . contains "imagemagick") True) -- https://github.com/NixOS/cabal2nix/issues/136
36 , ("jsaddle", set (dependencies . haskell . contains "ghcjs-base") False)
37 , ("mysql", set (libraryDepends . system . contains "mysql") True)
38 , ("pango", set (libraryDepends . haskell . contains "cairo") True)
39 , ("readline", over (libraryDepends . system) (Set.union (Set.fromList ["readline", "ncurses"])))
40 , ("terminfo", set (libraryDepends . system . contains "ncurses") True)
41 , ("thyme", set (libraryDepends . tool . contains "cpphs") True) -- required on Darwin
42 , ("monad", set phaseOverrides xmonadPostInstall)
43 , ("wxc", wxcHook)
44 , ("wxcore", set (libraryDepends . pkgconfig . contains "wxGTK") True)
45 , ("X11", over (libraryDepends . system) (Set.union (Set.fromList ["libXinerama","libXext","libXrender"])))
46 ]
48gitAnnexHook :: Derivation -> Derivation
49gitAnnexHook = set phaseOverrides gitAnnexOverrides . over (executableDepends . system) (Set.union buildInputs)
50 where
51 gitAnnexOverrides = unlines
52 [ "preConfigure = \"export HOME=$TEMPDIR; patchShebangs .\";"
53 , "postBuild = \"ln -sf dist/build/git-annex/git-annex git-annex\";"
54 , "installPhase = \"make PREFIX=$out CABAL=./Setup install\";"
55 , "checkPhase = \"./git-annex test\";"
56 ]
57 buildInputs = Set.fromList ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
59hfusePreConfigure :: String
60hfusePreConfigure = unlines
61 [ "preConfigure = ''"
62 , " sed -i -e \"s@ Extra-Lib-Dirs: /usr/local/lib@ Extra-Lib-Dirs: ${fuse}/lib@\" HFuse.cabal"
63 , "'';"
64 ]
66gfPhaseOverrides :: String
67gfPhaseOverrides = unlines
68 [ "postPatch = ''"
69 , " sed -i \"s|\\\"-s\\\"|\\\"\\\"|\" ./Setup.hs"
70 -- Disable silent compilation. Compiling takes long, it is best to see some
71 -- output, otherwise it looks like the build step has stalled.
72 , " sed -i \"s|numJobs (bf bi)++||\" ./Setup.hs"
73 -- Parallel compilation fails. Disable it.
74 , "'';"
75 , "preBuild = ''export LD_LIBRARY_PATH=`pwd`/dist/build:$LD_LIBRARY_PATH'';"
76 -- The build step itself, after having built the library, needs to be able
77 -- to find the library it just built in order to compile grammar files.
78 ]
80wxcHook :: Derivation -> Derivation
81wxcHook drv = drv & libraryDepends . system %~ Set.union (Set.fromList ["mesa", "libX11"])
82 & libraryDepends . pkgconfig . contains "wxGTK" .~ True
83 & phaseOverrides .~ wxcPostInstall (packageVersion drv)
84 & runHaddock .~ False
85 where
86 wxcPostInstall :: Version -> String
87 wxcPostInstall version = unlines
88 [ "postInstall = \"cp -v dist/build/libwxc.so." ++ display version ++ " $out/lib/libwxc.so\";"
89 , "postPatch = \"sed -i -e '/ldconfig inst_lib_dir/d' Setup.hs\";"
90 ]
92cabalInstallPostInstall :: String
93cabalInstallPostInstall = unlines
94 [ "postInstall = ''"
95 , " mkdir $out/etc"
96 , " mv bash-completion $out/etc/bash_completion.d"
97 , "'';"
98 ]
100darcsInstallPostInstall :: String
101darcsInstallPostInstall = unlines
102 [ "postInstall = ''"
103 , " mkdir -p $out/etc/bash_completion.d"
104 , " mv contrib/darcs_completion $out/etc/bash_completion.d/darcs"
105 , "'';"
106 ]
108xmonadPostInstall :: String
109xmonadPostInstall = unlines
110 [ "postInstall = ''"
111 , " shopt -s globstar"
112 , " mkdir -p $out/share/man/man1"
113 , " mv \"$out/\"**\"/man/\"*.1 $out/share/man/man1/"
114 , "'';"
115 ]
117agdaPostInstall :: String
118agdaPostInstall = unlines
119 [ "postInstall = ''"
120 , " $out/bin/agda -c --no-main $(find $out/share -name Primitive.agda)"
121 , " $out/bin/agda-mode compile"
122 , "'';"
123 ]
125{-
126postProcess' :: Derivation -> Derivation
127postProcess' deriv@(MkDerivation {..})
128 | pname == "alex" && version < Version [3,1] []
129 = deriv { buildTools = Set.insert "perl" buildTools }
130 | pname == "alex" && version >= Version [3,1] []
131 = deriv { buildTools = Set.insert "perl" (Set.insert "happy" buildTools) }
132 | pname == "apache-md5" = deriv { testDepends = Set.delete "crypto" testDepends }
133 | pname == "bits-extras" = deriv { configureFlags = Set.insert "--ghc-option=-lgcc_s" configureFlags
134 , extraLibs = Set.filter (/= "gcc_s") extraLibs
135 }
136 | pname == "Cabal" = deriv { phaseOverrides = "preCheck = \"unset GHC_PACKAGE_PATH; export HOME=$NIX_BUILD_TOP\";" }
137 | pname == "cabal-bounds" = deriv { buildTools = Set.insert "cabal-install" buildTools }
138 | pname == "editline" = deriv { extraLibs = Set.insert "libedit" extraLibs }
139 | pname == "ghc-heap-view" = deriv { phaseOverrides = ghciPostInstall }
140 | pname == "ghc-mod" = deriv { phaseOverrides = ghcModPostInstall pname version, buildTools = Set.insert "emacs" buildTools }
141 | pname == "ghc-parser" = deriv { buildTools = Set.insert "cpphs" (Set.insert "happy" buildTools)
142 , phaseOverrides = ghcParserPatchPhase }
143 | pname == "ghc-vis" = deriv { phaseOverrides = ghciPostInstall }
144 | pname == "github-backup" = deriv { buildTools = Set.insert "git" buildTools }
145 | pname == "gloss-raster" = deriv { extraLibs = Set.insert "llvm" extraLibs }
146 | pname == "GLUT" = deriv { extraLibs = Set.fromList ["glut","libSM","libICE","libXmu","libXi","mesa"] `Set.union` extraLibs }
147 | pname == "gtkglext" = deriv { pkgConfDeps = Set.insert "pangox_compat" pkgConfDeps }
148 | pname == "gtk2hs-buildtools"= deriv { buildDepends = Set.insert "hashtables" buildDepends }
149 | pname == "haddock" && version < Version [2,14] []
150 = deriv { buildTools = Set.insert "alex" (Set.insert "happy" buildTools) }
151 | pname == "happy" = deriv { buildTools = Set.insert "perl" buildTools }
152 | pname == "haskeline" = deriv { buildDepends = Set.insert "utf8-string" buildDepends }
153 | pname == "haskell-src" = deriv { buildTools = Set.insert "happy" buildTools }
154 | pname == "haskell-src-meta" = deriv { buildDepends = Set.insert "uniplate" buildDepends }
155 | pname == "hlibgit2" = deriv { buildTools = Set.insert "git" buildTools }
156 | pname == "HList" = deriv { buildTools = Set.insert "diffutils" buildTools }
157 | pname == "hmatrix" = deriv { extraLibs = Set.insert "liblapack" (Set.insert "blas" (Set.filter (/= "lapack") extraLibs)) }
158 | pname == "hmatrix-special" = deriv { extraLibs = Set.insert "gsl" extraLibs }
159 | pname == "idris" = deriv { buildTools = Set.insert "happy" buildTools, extraLibs = Set.insert "gmp" (Set.insert "boehmgc" extraLibs) }
160 | pname == "inline-c-cpp" = deriv { testDepends = Set.delete "stdc++" testDepends }
161 | pname == "language-c-quote" = deriv { buildTools = Set.insert "alex" (Set.insert "happy" buildTools) }
162 | pname == "language-java" = deriv { buildDepends = Set.insert "syb" buildDepends }
163 | pname == "lhs2tex" = deriv { extraLibs = Set.insert "texLive" extraLibs, phaseOverrides = lhs2texPostInstall }
164 | pname == "libffi" = deriv { extraLibs = Set.delete "ffi" extraLibs }
165 | pname == "liquid-fixpoint" = deriv { buildTools = Set.insert "z3" (Set.insert "ocaml" buildTools), configureFlags = Set.insert "-fbuild-external" configureFlags }
166 | pname == "liquidhaskell" = deriv { buildTools = Set.insert "z3" buildTools }
167 | pname == "MFlow" = deriv { buildTools = Set.insert "cpphs" buildTools }
168 | pname == "multiarg" = deriv { buildDepends = Set.insert "utf8-string" buildDepends }
169 | pname == "ncurses" = deriv { phaseOverrides = ncursesPatchPhase }
170 | pname == "Omega" = deriv { testDepends = Set.delete "stdc++" testDepends }
171 | pname == "OpenAL" = deriv { extraLibs = Set.insert "openal" extraLibs }
172 | pname == "OpenGL" = deriv { extraLibs = Set.insert "mesa" (Set.insert "libX11" extraLibs) }
173 | pname == "pandoc" = deriv { buildDepends = Set.insert "alex" (Set.insert "happy" buildDepends) }
174 | pname == "persistent" = deriv { extraLibs = Set.insert "sqlite3" extraLibs }
175 | pname == "purescript" = deriv { buildTools = Set.insert "nodejs" buildTools }
176 | pname == "repa-algorithms" = deriv { extraLibs = Set.insert "llvm" extraLibs }
177 | pname == "repa-examples" = deriv { extraLibs = Set.insert "llvm" extraLibs }
178 | pname == "SDL-image" = deriv { extraLibs = Set.insert "SDL_image" extraLibs }
179 | pname == "SDL-mixer" = deriv { extraLibs = Set.insert "SDL_mixer" extraLibs }
180 | pname == "SDL-ttf" = deriv { extraLibs = Set.insert "SDL_ttf" extraLibs }
181 | pname == "sloane" = deriv { phaseOverrides = sloanePostInstall }
182 | pname == "structured-haskell-mode" = deriv { buildTools = Set.insert "emacs" buildTools
183 , phaseOverrides = structuredHaskellModePostInstall
184 }
185 | pname == "target" = deriv { buildTools = Set.insert "z3" buildTools }
186 | pname == "threadscope" = deriv { configureFlags = Set.insert "--ghc-options=-rtsopts" configureFlags }
187 | pname == "vacuum" = deriv { extraLibs = Set.insert "ghc-paths" extraLibs }
188 | pname == "wxcore" = deriv { extraLibs = Set.fromList ["wxGTK","mesa","libX11"] `Set.union` extraLibs }
189 | pname == "X11-xft" = deriv { extraLibs = Set.fromList ["pkgconfig","freetype","fontconfig"] `Set.union` extraLibs
190 , configureFlags = Set.insert "--extra-include-dirs=${freetype}/include/freetype2" configureFlags
191 }
192-- Unbreak packages during hackage2nix generation:
194 | pname == "hnetcdf" = deriv { testDepends = Set.delete "netcdf" testDepends }
195 | pname == "SDL2-ttf" = deriv { buildDepends = Set.delete "SDL2" buildDepends }
196 | pname == "hzk" = deriv { testDepends = Set.delete "zookeeper_mt" testDepends, buildTools = Set.insert "zookeeper_mt" buildTools }
197 | pname == "z3" = deriv { phaseOverrides = "preBuild = stdenv.lib.optionalString stdenv.isDarwin \"export DYLD_LIBRARY_PATH=${z3}/lib\";" }
198 | pname == "zip-archive" = deriv { testDepends = Set.delete "zip" testDepends, buildTools = Set.insert "zip" buildTools }
199 | otherwise = deriv
201ghcModPostInstall :: String -> Version -> String
202ghcModPostInstall pname version = unlines
203 [ "configureFlags = \"--datasubdir=" ++ pname ++ "-" ++ display version ++ "\";"
204 , "postInstall = ''"
205 , " cd $out/share/" ++ pname ++ "-" ++ display version
206 , " make"
207 , " rm Makefile"
208 , " cd .."
209 , " ensureDir \"$out/share/emacs\""
210 , " mv " ++ pname ++ "-" ++ display version ++ " emacs/site-lisp"
211 , "'';"
212 ]
214ghciPostInstall :: String
215ghciPostInstall = unlines
216 [ "postInstall = ''"
217 , " ensureDir \"$out/share/ghci\""
218 , " ln -s \"$out/share/$pname-$version/ghci\" \"$out/share/ghci/$pname\""
219 , "'';"
220 ]
223lhs2texPostInstall :: String
224lhs2texPostInstall = unlines
225 [ "postInstall = ''"
226 , " mkdir -p \"$out/share/doc/$name\""
227 , " cp doc/Guide2.pdf $out/share/doc/$name"
228 , " mkdir -p \"$out/nix-support\""
229 , "'';"
230 ]
232ncursesPatchPhase :: String
233ncursesPatchPhase = "patchPhase = \"find . -type f -exec sed -i -e 's|ncursesw/||' {} \\\\;\";"
236structuredHaskellModePostInstall :: String
237structuredHaskellModePostInstall = unlines
238 [ "postInstall = ''"
239 , " emacs -L elisp --batch -f batch-byte-compile \"elisp/\"*.el"
240 , " install -d $out/share/emacs/site-lisp"
241 , " install \"elisp/\"*.el \"elisp/\"*.elc $out/share/emacs/site-lisp"
242 , "'';"
243 ]
245sloanePostInstall :: String
246sloanePostInstall = unlines
247 [ "postInstall = ''"
248 , " mkdir -p $out/share/man/man1"
249 , " cp sloane.1 $out/share/man/man1/"
250 , "'';"
251 ]
253haddockPreCheck :: String
254haddockPreCheck = "preCheck = \"unset GHC_PACKAGE_PATH\";"
256ghcParserPatchPhase :: String
257ghcParserPatchPhase = unlines
258 [ "patchPhase = ''"
259 , " substituteInPlace build-parser.sh --replace \"/bin/bash\" \"$SHELL\""
260 , "'';"
261 ]
263-}