git.iko.soy/typeable/cabal2nix
on 58dbc29 help sign in
271 lines 13 kB history raw
1{-# LANGUAGE RecordWildCards #-}
3module Cabal2Nix.PostProcess ( postProcess ) where
5import Distribution.NixOS.Derivation.Cabal
6import Data.List
8postProcess :: Derivation -> Derivation
9postProcess deriv@(MkDerivation {..})
10 | pname == "aeson" && version > Version [0,7] []
11 = deriv { buildDepends = "blazeBuilder":buildDepends }
12 | pname == "Agda" = deriv { buildTools = "emacs":buildTools, phaseOverrides = agdaPostInstall }
13 | pname == "alex" && version < Version [3,1] []
14 = deriv { buildTools = "perl":buildTools }
15 | pname == "alex" && version >= Version [3,1] []
16 = deriv { buildTools = "perl":"happy":buildTools }
17 | pname == "cabal2nix" = deriv { doCheck = True, phaseOverrides = cabal2nixDoCheckHook }
18 | pname == "cabal-install" && version >= Version [0,14] []
19 = deriv { phaseOverrides = cabalInstallPostInstall }
20 | pname == "cairo" = deriv { extraLibs = "pkgconfig":"libc":"cairo":"zlib":extraLibs }
21 | pname == "cuda" = deriv { phaseOverrides = cudaConfigurePhase, extraLibs = "cudatoolkit":"nvidia_x11":"self.stdenv.gcc":extraLibs }
22 | pname == "darcs" = deriv { phaseOverrides = darcsInstallPostInstall }
23 | pname == "dns" = deriv { testTarget = "spec" }
24 | pname == "doctest" = deriv { runHaddock = True, phaseOverrides = doctestNoHaddock }
25 | pname == "editline" = deriv { extraLibs = "libedit":extraLibs }
26 | pname == "epic" = deriv { extraLibs = "gmp":"boehmgc":extraLibs, buildTools = "happy":buildTools }
27 | pname == "either" = deriv { runHaddock = True, phaseOverrides = eitherNoHaddock }
28 | pname == "ghc-heap-view" = deriv { phaseOverrides = ghciPostInstall }
29 | pname == "ghc-mod" = deriv { phaseOverrides = ghcModPostInstall, buildTools = "emacs":buildTools }
30 | pname == "ghc-paths" = deriv { phaseOverrides = ghcPathsPatches }
31 | pname == "ghc-vis" = deriv { phaseOverrides = ghciPostInstall }
32 | pname == "git-annex" = deriv { phaseOverrides = gitAnnexOverrides, buildTools = "git":"rsync":"gnupg1":"curl":"lsof":"openssh":"which":"bup":"perl":buildTools }
33 | pname == "github-backup" = deriv { buildTools = "git":buildTools }
34 | pname == "glade" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, pkgConfDeps = "gtkC":delete "gtk" pkgConfDeps }
35 | pname == "glib" = deriv { extraLibs = "pkgconfig":"libc":extraLibs }
36 | pname == "gloss-raster" = deriv { extraLibs = "llvm":extraLibs }
37 | pname == "GLUT" = deriv { extraLibs = "glut":"libSM":"libICE":"libXmu":"libXi":"mesa":extraLibs }
38 | pname == "gtk" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, buildDepends = delete "gio" buildDepends }
39 | pname == "gtksourceview2" = deriv { extraLibs = "pkgconfig":"libc":extraLibs }
40 | pname == "haddock" = deriv { buildTools = "alex":"happy":buildTools }
41 | pname == "happy" = deriv { buildTools = "perl":buildTools }
42 | pname == "haskeline" = deriv { buildDepends = "utf8String":buildDepends }
43 | pname == "haskell-src" = deriv { buildTools = "happy":buildTools }
44 | pname == "haskell-src-meta" = deriv { buildDepends = "uniplate":buildDepends }
45 | pname == "hflags" = deriv { metaSection = metaSection { license = Unknown (Just "Apache-2.0") } }
46 | pname == "HFuse" = deriv { phaseOverrides = hfusePreConfigure }
47 | pname == "highlighting-kate"= highlightingKatePostProcessing deriv
48 | pname == "HList" = deriv { buildTools = "diffutils":buildTools }
49 | pname == "hmatrix" = deriv { extraLibs = "gsl":"liblapack":"blas":extraLibs }
50 | pname == "hoogle" = deriv { testTarget = "--test-option=--no-net" }
51 | pname == "hspec" = deriv { doCheck = False }
52 | pname == "idris" = deriv { buildTools = "happy":buildTools, extraLibs = "gmp":"boehmgc":extraLibs }
53 | pname == "language-c-quote" = deriv { buildTools = "alex":"happy":buildTools }
54 | pname == "language-java" = deriv { buildDepends = "syb":buildDepends }
55 | pname == "leksah-server" = deriv { buildDepends = "process-leksah":buildDepends }
56 | pname == "lhs2tex" = deriv { extraLibs = "texLive":extraLibs, phaseOverrides = lhs2texPostInstall }
57 | pname == "libffi" = deriv { extraLibs = delete "ffi" extraLibs }
58 | pname == "llvm-base" = deriv { extraLibs = "llvm":extraLibs }
59 | pname == "llvm-general" = deriv { doCheck = False }
60 | pname == "llvm-general-pure"= deriv { doCheck = False }
61 | pname == "markdown-unlit" = deriv { runHaddock = True, phaseOverrides = markdownUnlitNoHaddock }
62 | pname == "multiarg" = deriv { buildDepends = "utf8String":buildDepends }
63 | pname == "mime-mail" = deriv { extraFunctionArgs = ["sendmail ? \"sendmail\""], phaseOverrides = mimeMailConfigureFlags }
64 | pname == "mysql" = deriv { buildTools = "mysqlConfig":buildTools, extraLibs = "zlib":extraLibs }
65 | pname == "ncurses" = deriv { phaseOverrides = ncursesPatchPhase }
66 | pname == "OpenAL" = deriv { extraLibs = "openal":extraLibs }
67 | pname == "OpenGL" = deriv { extraLibs = "mesa":"libX11":extraLibs }
68 | pname == "pandoc" = deriv { buildDepends = "alex":"happy":buildDepends }
69 | pname == "pango" = deriv { extraLibs = "pkgconfig":"libc":extraLibs }
70 | pname == "pcap" = deriv { extraLibs = "libpcap":extraLibs }
71 | pname == "persistent" = deriv { extraLibs = "sqlite3":extraLibs }
72 | pname == "poppler" = deriv { extraLibs = "libc":extraLibs }
73 | pname == "repa-algorithms" = deriv { extraLibs = "llvm":extraLibs }
74 | pname == "repa-examples" = deriv { extraLibs = "llvm":extraLibs }
75 | pname == "SDL-image" = deriv { extraLibs = "SDL_image":extraLibs }
76 | pname == "SDL-mixer" = deriv { extraLibs = "SDL_mixer":extraLibs }
77 | pname == "SDL-ttf" = deriv { extraLibs = "SDL_ttf":extraLibs }
78 | pname == "sloane" = deriv { phaseOverrides = sloanePostInstall }
79 | pname == "structured-haskell-mode" = deriv { buildTools = "emacs":buildTools, phaseOverrides = structuredHaskellModePostInstall }
80 | pname == "svgcairo" = deriv { extraLibs = "libc":extraLibs }
81 | pname == "terminfo" = deriv { extraLibs = "ncurses":extraLibs }
82 | pname == "threadscope" = deriv { configureFlags = "--ghc-options=-rtsopts":configureFlags }
83 | pname == "unix-time" = deriv { phaseOverrides = unixTimeConfigureFlags }
84 | pname == "vacuum" = deriv { extraLibs = "ghcPaths":extraLibs }
85 | pname == "wxc" = deriv { extraLibs = "wxGTK":"mesa":"libX11":extraLibs, phaseOverrides = wxcPostInstall }
86 | pname == "wxcore" = deriv { extraLibs = "wxGTK":"mesa":"libX11":extraLibs }
87 | pname == "X11" && version >= Version [1,6] []
88 = deriv { extraLibs = "libXinerama":"libXext":"libXrender":extraLibs }
89 | pname == "X11" = deriv { extraLibs = "libXinerama":"libXext":extraLibs }
90 | pname == "X11-xft" = deriv { extraLibs = "pkgconfig":"freetype":"fontconfig":extraLibs
91 , configureFlags = "--extra-include-dirs=${freetype}/include/freetype2":configureFlags
92 }
93 | pname == "xmonad" = deriv { phaseOverrides = xmonadPostInstall }
94 | otherwise = deriv
96cudaConfigurePhase :: String
97cudaConfigurePhase = unlines
98 [ "# Perhaps this should be the default in cabal.nix ..."
99 , "#"
100 , "# The cudatoolkit provides both 64 and 32-bit versions of the"
101 , "# library. GHC's linker fails if the wrong version is found first."
102 , "# We solve this by eliminating lib64 from the path on 32-bit"
103 , "# platforms and putting lib64 first on 64-bit platforms."
104 , "libPaths = if self.stdenv.is64bit then \"lib64 lib\" else \"lib\";"
105 , "configurePhase = ''"
106 , " for i in Setup.hs Setup.lhs; do"
107 , " test -f $i && ghc --make $i"
108 , " done"
109 , " for p in $extraBuildInputs $propagatedNativeBuildInputs; do"
110 , " if [ -d \"$p/include\" ]; then"
111 , " extraLibDirs=\"$extraLibDirs --extra-include-dir=$p/include\""
112 , " fi"
113 , " for d in $libPaths; do"
114 , " if [ -d \"$p/$d\" ]; then"
115 , " extraLibDirs=\"$extraLibDirs --extra-lib-dir=$p/$d\""
116 , " fi"
117 , " done"
118 , " done"
119 , " ./Setup configure --verbose --prefix=\"$out\" $libraryProfiling $extraLibDirs $configureFlags"
120 , "'';"
121 ]
123ghcModPostInstall :: String
124ghcModPostInstall = unlines
125 [ "postInstall = ''"
126 , " cd $out/share/$pname-$version"
127 , " make"
128 , " rm Makefile"
129 , " cd .."
130 , " ensureDir \"$out/share/emacs\""
131 , " mv $pname-$version emacs/site-lisp"
132 , " mv $out/bin/ghc-mod $out/bin/.ghc-mod-wrapped"
133 , " cat - > $out/bin/ghc-mod <<EOF"
134 , " #! ${self.stdenv.shell}"
135 , " COMMAND=\\$1"
136 , " shift"
137 , " eval exec $out/bin/.ghc-mod-wrapped \\$COMMAND \\$( ${self.ghc.GHCGetPackages} ${self.ghc.version} | tr \" \" \"\\n\" | tail -n +2 | paste -d \" \" - - | sed 's/.*/-g \"&\"/' | tr \"\\n\" \" \") \"\\$@\""
138 , " EOF"
139 , " chmod +x $out/bin/ghc-mod"
140 , "'';"
141 ]
143wxcPostInstall :: String
144wxcPostInstall = unlines
145 [ "postInstall = ''"
146 , " cp -v dist/build/libwxc.so.${self.version} $out/lib/libwxc.so"
147 , "'';"
148 ]
150cabalInstallPostInstall :: String
151cabalInstallPostInstall = unlines
152 [ "postInstall = ''"
153 , " mkdir $out/etc"
154 , " mv bash-completion $out/etc/bash_completion.d"
155 , "'';"
156 ]
158darcsInstallPostInstall :: String
159darcsInstallPostInstall = unlines
160 [ "postInstall = ''"
161 , " mkdir -p $out/etc/bash_completion.d"
162 , " mv contrib/darcs_completion $out/etc/bash_completion.d/darcs"
163 , "'';"
164 ]
166highlightingKatePostProcessing :: Derivation -> Derivation
167highlightingKatePostProcessing deriv@(MkDerivation {..}) = deriv
168 { phaseOverrides = "prePatch = \"sed -i -e 's|regex-pcre-builtin|regex-pcre|' highlighting-kate.cabal\";"
169 , buildDepends = "regex-pcre" : filter (/="regex-pcre-builtin") buildDepends
170 }
172xmonadPostInstall :: String
173xmonadPostInstall = unlines
174 [ "postInstall = ''"
175 , " shopt -s globstar"
176 , " mkdir -p $out/share/man/man1"
177 , " mv \"$out/\"**\"/man/\"*.1 $out/share/man/man1/"
178 , "'';"
179 ]
181gitAnnexOverrides :: String
182gitAnnexOverrides = unlines
183 [ "preConfigure = ''"
184 , " export HOME=\"$NIX_BUILD_TOP/tmp\""
185 , " mkdir \"$HOME\""
186 , "'';"
187 , "installPhase = \"./Setup install\";"
188 , "checkPhase = ''"
189 , " cp dist/build/git-annex/git-annex git-annex"
190 , " ./git-annex test"
191 , "'';"
192 , "propagatedUserEnvPkgs = [git lsof];"
193 ]
195ghciPostInstall :: String
196ghciPostInstall = unlines
197 [ "postInstall = ''"
198 , " ensureDir \"$out/share/ghci\""
199 , " ln -s \"$out/share/$pname-$version/ghci\" \"$out/share/ghci/$pname\""
200 , "'';"
201 ]
203hfusePreConfigure :: String
204hfusePreConfigure = unlines
205 [ "preConfigure = ''"
206 , " sed -i -e \"s@ Extra-Lib-Dirs: /usr/local/lib@ Extra-Lib-Dirs: ${fuse}/lib@\" HFuse.cabal"
207 , " sed -i -e \"s/LANGUAGE FlexibleContexts/LANGUAGE FlexibleContexts, RankNTypes/\" System/Fuse.hsc"
208 , " sed -i -e \"s/E(Exception/E(catch, Exception, IOException/\" System/Fuse.hsc"
209 , " sed -i -e \"s/IO(catch,/IO(/\" System/Fuse.hsc"
210 , " sed -i -e \"s/IO.catch/ E.catch/\" System/Fuse.hsc"
211 , " sed -i -e \"s/const exitFailure/\\\\\\\\(_ :: IOException) -> exitFailure/\" System/Fuse.hsc"
212 , "'';"
213 ]
215ghcPathsPatches :: String
216ghcPathsPatches = "patches = [ ./ghc-paths-nix.patch ];"
218lhs2texPostInstall :: String
219lhs2texPostInstall = unlines
220 [ "postInstall = ''"
221 , " mkdir -p \"$out/share/doc/$name\""
222 , " cp doc/Guide2.pdf $out/share/doc/$name"
223 , " mkdir -p \"$out/nix-support\""
224 , "'';"
225 ]
227ncursesPatchPhase :: String
228ncursesPatchPhase = "patchPhase = \"find . -type f -exec sed -i -e 's|ncursesw/||' {} \\\\;\";"
230doctestNoHaddock, markdownUnlitNoHaddock :: String
231markdownUnlitNoHaddock = "noHaddock = self.stdenv.lib.versionOlder self.ghc.version \"7.4\";"
232doctestNoHaddock = markdownUnlitNoHaddock
234cabal2nixDoCheckHook :: String
235cabal2nixDoCheckHook = "doCheck = self.stdenv.lib.versionOlder \"7.6\" self.ghc.version;"
237eitherNoHaddock :: String
238eitherNoHaddock = "noHaddock = self.stdenv.lib.versionOlder self.ghc.version \"7.6\";"
240agdaPostInstall :: String
241agdaPostInstall = unlines
242 [ "postInstall = ''"
243 , " $out/bin/agda-mode compile"
244 , "'';"
245 ]
247structuredHaskellModePostInstall :: String
248structuredHaskellModePostInstall = unlines
249 [ "postInstall = ''"
250 , " emacs -L elisp --batch -f batch-byte-compile \"elisp/\"*.el"
251 , " install -d $out/share/emacs/site-lisp"
252 , " install \"elisp/\"*.el \"elisp/\"*.elc $out/share/emacs/site-lisp"
253 , "'';"
254 ]
256unixTimeConfigureFlags :: String
257unixTimeConfigureFlags =
258 "configureFlags = self.stdenv.lib.optionalString self.enableSharedLibraries \"--ghc-option=-fPIC\";"
260sloanePostInstall :: String
261sloanePostInstall = unlines
262 [ "postInstall = ''"
263 , " mkdir -p $out/share/man/man1"
264 , " cp sloane.1 $out/share/man/man1/"
265 , "'';"
266 ]
268mimeMailConfigureFlags :: String
269mimeMailConfigureFlags = unlines
270 [ "configureFlags = \"--ghc-option=-DMIME_MAIL_SENDMAIL_PATH=\\\"${sendmail}\\\"\";"
271 ]