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