@@ -1,330 +0,0 @@
1−# generic builder for Cabal packages
2−
3−{ stdenv, fetchurl, lib, pkgconfig, ghc, Cabal, jailbreakCabal, glibcLocales
4−, gnugrep, coreutils, hscolour, cpphs
5−, enableLibraryProfiling ? false
6−, enableSharedLibraries ? false
7−, enableSharedExecutables ? false
8−, enableStaticLibraries ? true
9−, enableCheckPhase ? stdenv.lib.versionOlder "7.4" ghc.version
10−, enableHyperlinkSource ? true
11−, enableCpphs ? false
12−, extension ? (self : super : {})
13−}:
14−
15−let
16− enableFeature = stdenv.lib.enableFeature;
17− versionOlder = stdenv.lib.versionOlder;
18− optional = stdenv.lib.optional;
19− optionals = stdenv.lib.optionals;
20− optionalString = stdenv.lib.optionalString;
21− filter = stdenv.lib.filter;
22−
23− defaultSetupHs = builtins.toFile "Setup.hs" ''
24− import Distribution.Simple
25− main = defaultMain
26− '';
27−in
28−
29−# Cabal shipped with GHC 6.12.4 or earlier doesn't know the "--enable-tests configure" flag.
30−assert enableCheckPhase -> versionOlder "7" ghc.version;
31−
32−# GHC prior to 7.4.x doesn't know the "--enable-executable-dynamic" flag.
33−assert enableSharedExecutables -> versionOlder "7.4" ghc.version;
34−
35−# Our GHC 6.10.x builds do not provide sharable versions of their core libraries.
36−assert enableSharedLibraries -> versionOlder "6.12" ghc.version;
37−
38−# Pure shared library builds don't work before GHC 7.8.x.
39−assert !enableStaticLibraries -> versionOlder "7.7" ghc.version;
40−
41−{
42− mkDerivation =
43− args : # arguments for the individual package, can modify the defaults
44− let # These attributes are removed in the end. This is in order not to spoil the build
45− # environment overly, but also to keep hash-backwards-compatible with the old cabal.nix.
46− internalAttrs = [
47− "internalAttrs" "buildDepends" "buildTools" "extraLibraries" "pkgconfigDepends"
48− "isLibrary" "isExecutable" "testDepends"
49− ];
50−
51− # Stuff happening after the user preferences have been processed. We remove
52− # internal attributes and strip null elements from the dependency lists, all
53− # in the interest of keeping hashes stable.
54− postprocess =
55− x : (removeAttrs x internalAttrs) // {
56− buildInputs = filter (y : ! (y == null)) x.buildInputs;
57− propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs;
58− propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs;
59− doCheck = enableCheckPhase && x.doCheck;
60− useCpphs = enableCpphs && x.useCpphs;
61− hyperlinkSource = enableHyperlinkSource && x.hyperlinkSource;
62− # Disable Darwin builds: <https://github.com/NixOS/nixpkgs/issues/2689>.
63− meta = let meta = x.meta or {};
64− hydraPlatforms = meta.hydraPlatforms or meta.platforms or [];
65− noElem = p: ps: !stdenv.lib.elem p ps;
66− noDarwin = p: noElem p stdenv.lib.platforms.darwin;
67− in
68− meta // { hydraPlatforms = filter noDarwin hydraPlatforms; };
69− };
70−
71− defaults =
72− self : { # self is the final version of the attribute set
73−
74− # pname should be defined by the client to be the package basename
75− # version should be defined by the client to be the package version
76−
77− # fname is the internal full name of the package
78− fname = "${self.pname}-${self.version}";
79−
80− # name is the external full name of the package; usually we prefix
81− # all packages with haskell- to avoid name clashes for libraries;
82− # if that is not desired (for applications), name can be set to
83− # fname.
84− name = if self.isLibrary then
85− if enableLibraryProfiling && self.enableSharedLibraries then
86− "haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}-profiling-shared"
87− else if enableLibraryProfiling && !self.enableSharedLibraries then
88− "haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}-profiling"
89− else if !enableLibraryProfiling && self.enableSharedLibraries then
90− "haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}-shared"
91− else
92− "haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}"
93− else
94− "${self.pname}-${self.version}";
95−
96− # the default download location for Cabal packages is Hackage,
97− # you still have to specify the checksum
98− src = fetchurl {
99− url = "mirror://hackage/${self.pname}/${self.fname}.tar.gz";
100− inherit (self) sha256;
101− };
102−
103− # default buildInputs are just ghc, if more buildInputs are required
104− # buildInputs can be extended by the client by using extraBuildInputs,
105− # but often propagatedBuildInputs is preferable anyway
106− buildInputs = [ghc Cabal] ++ self.extraBuildInputs;
107− extraBuildInputs = self.buildTools ++
108− (optionals self.doCheck self.testDepends) ++
109− (optional self.hyperlinkSource hscolour) ++
110− (optional self.useCpphs cpphs) ++
111− (if self.pkgconfigDepends == [] then [] else [pkgconfig]) ++
112− (if self.isLibrary then [] else self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends);
113−
114− # we make sure that propagatedBuildInputs is defined, so that we don't
115− # have to check for its existence
116− propagatedBuildInputs = if self.isLibrary then self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends else [];
117−
118− # By default, also propagate all dependencies to the user environment. This is required, otherwise packages would be broken, because
119− # GHC also needs all dependencies to be available.
120− propagatedUserEnvPkgs = if self.isLibrary then self.buildDepends else [];
121−
122− # library directories that have to be added to the Cabal files
123− extraLibDirs = [];
124−
125− # build-depends Cabal field
126− buildDepends = [];
127−
128− # target(s) passed to the cabal build phase as an argument
129− buildTarget = "";
130−
131− # build-depends Cabal fields stated in test-suite stanzas
132− testDepends = [];
133−
134− # target(s) passed to the cabal test phase as an argument
135− testTarget = "";
136−
137− # build-tools Cabal field
138− buildTools = [];
139−
140− # extra-libraries Cabal field
141− extraLibraries = [];
142−
143− # pkgconfig-depends Cabal field
144− pkgconfigDepends = [];
145−
146− isLibrary = ! self.isExecutable;
147− isExecutable = false;
148−
149− # ignore version restrictions on the build inputs that the cabal file might specify
150− jailbreak = false;
151−
152− # pass the '--enable-split-objs' flag to cabal in the configure stage
153− enableSplitObjs = !stdenv.isDarwin; # http://hackage.haskell.org/trac/ghc/ticket/4013
154−
155− # pass the '--enable-tests' flag to cabal in the configure stage
156− # and run any regression test suites the package might have
157− doCheck = enableCheckPhase;
158−
159− # force cpphs instead of the C compiler's preprocessor; sometimes
160− # needed due to clang's wacky behavior
161− useCpphs = false;
162−
163− # pass the '--hyperlink-source' flag to ./Setup haddock
164− hyperlinkSource = enableHyperlinkSource;
165−
166− # abort the build if the configure phase detects that the package
167− # depends on multiple versions of the same build input
168− strictConfigurePhase = true;
169−
170− # pass the '--enable-library-vanilla' flag to cabal in the
171− # configure stage to enable building shared libraries
172− inherit enableStaticLibraries;
173−
174− # pass the '--enable-shared' flag to cabal in the configure
175− # stage to enable building shared libraries
176− inherit enableSharedLibraries;
177−
178− # pass the '--enable-executable-dynamic' flag to cabal in
179− # the configure stage to enable linking shared libraries
180− inherit enableSharedExecutables;
181−
182− extraConfigureFlags = [
183− (enableFeature self.enableSplitObjs "split-objs")
184− (enableFeature enableLibraryProfiling "library-profiling")
185− (enableFeature self.enableSharedLibraries "shared")
186− (optional (versionOlder "7" ghc.version) (enableFeature self.enableStaticLibraries "library-vanilla"))
187− (optional (versionOlder "7.4" ghc.version) (enableFeature self.enableSharedExecutables "executable-dynamic"))
188− (optional (versionOlder "7" ghc.version) (enableFeature self.doCheck "tests"))
189− ];
190−
191− # GHC needs the locale configured during the Haddock phase.
192− LANG = "en_US.UTF-8";
193− LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive";
194−
195− # compiles Setup and configures
196− configurePhase = ''
197− eval "$preConfigure"
198−
199− ${let newCabalFile = fetchurl {
200− url = "http://hackage.haskell.org/package/${self.fname}/${self.pname}.cabal";
201− sha256 = self.editedCabalFile;
202− };
203− in
204− optionalString (self.editedCabalFile or "" != "") ''
205− echo "Replace Cabal file with edited version ${newCabalFile}."
206− cp ${newCabalFile} ${self.pname}.cabal
207− ''
208− }${optionalString self.jailbreak "${jailbreakCabal}/bin/jailbreak-cabal ${self.pname}.cabal"}
209−
210− for i in Setup.hs Setup.lhs ${defaultSetupHs}; do
211− test -f $i && break
212− done
213− ghc --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
214−
215− for p in $extraBuildInputs $propagatedNativeBuildInputs; do
216− if [ -d "$p/lib/ghc-${ghc.ghc.version}/package.conf.d" ]; then
217− # Haskell packages don't need any extra configuration.
218− continue;
219− fi
220− if [ -d "$p/include" ]; then
221− extraConfigureFlags+=" --extra-include-dirs=$p/include"
222− fi
223− for d in lib{,64}; do
224− if [ -d "$p/$d" ]; then
225− extraConfigureFlags+=" --extra-lib-dirs=$p/$d"
226− fi
227− done
228− done
229−
230− configureFlags+=" --with-gcc=$CC"
231−
232− ${optionalString (self.enableSharedExecutables && self.stdenv.isLinux) ''
233− configureFlags+=" --ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.ghc.name}/${self.pname}-${self.version}"
234− ''}
235− ${optionalString (self.enableSharedExecutables && self.stdenv.isDarwin) ''
236− configureFlags+=" --ghc-option=-optl=-Wl,-headerpad_max_install_names"
237− ''}
238− ${optionalString (versionOlder "7.8" ghc.version && !self.isLibrary) ''
239− configureFlags+=" --ghc-option=-j$NIX_BUILD_CORES"
240− ''}
241− ${optionalString self.useCpphs ''
242− configureFlags+=" --ghc-option=-pgmPcpphs --ghc-option=-optP--cpp"
243− ''}
244−
245− ${optionalString self.stdenv.isDarwin ''
246− configureFlags+=" --with-gcc=clang"
247− ''}
248−
249− echo "configure flags: $extraConfigureFlags $configureFlags"
250− ./Setup configure --verbose --prefix="$out" --libdir='$prefix/lib/$compiler' \
251− --libsubdir='$pkgid' $extraConfigureFlags $configureFlags 2>&1 \
252− ${optionalString self.strictConfigurePhase ''
253− | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log"
254− if ${gnugrep}/bin/egrep -q '^Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then
255− echo >&2 "*** abort because of serious configure-time warning from Cabal"
256− exit 1
257− fi
258− ''}
259−
260− eval "$postConfigure"
261− '';
262−
263− # builds via Cabal
264− buildPhase = ''
265− eval "$preBuild"
266−
267− ./Setup build ${self.buildTarget}
268−
269− export GHC_PACKAGE_PATH=$(${ghc.GHCPackages})
270− test -n "$noHaddock" || ./Setup haddock --html --hoogle \
271− ${optionalString (stdenv.lib.versionOlder "6.12" ghc.version) "--ghc-options=-optP-P"} \
272− ${optionalString self.hyperlinkSource "--hyperlink-source"} \
273− ${optionalString self.useCpphs ''
274− --haddock-options="--optghc=-pgmPcpphs --optghc=-optP--cpp"
275− ''}
276−
277− eval "$postBuild"
278− '';
279−
280− checkPhase = optional self.doCheck ''
281− eval "$preCheck"
282−
283− ./Setup test ${self.testTarget}
284−
285− eval "$postCheck"
286− '';
287−
288− # installs via Cabal; creates a registration file for nix-support
289− # so that the package can be used in other Haskell-builds; also
290− # adds all propagated build inputs to the user environment packages
291− installPhase = ''
292− eval "$preInstall"
293−
294− ./Setup copy
295−
296− mkdir -p $out/bin # necessary to get it added to PATH
297−
298− local confDir=$out/lib/ghc-${ghc.ghc.version}/package.conf.d
299− local installedPkgConf=$confDir/${self.fname}.installedconf
300− local pkgConf=$confDir/${self.fname}.conf
301− mkdir -p $confDir
302− ./Setup register --gen-pkg-config=$pkgConf
303− if test -f $pkgConf; then
304− echo '[]' > $installedPkgConf
305− GHC_PACKAGE_PATH=$installedPkgConf ghc-pkg --global register $pkgConf --force
306− fi
307−
308− if test -f $out/nix-support/propagated-native-build-inputs; then
309− ln -s $out/nix-support/propagated-native-build-inputs $out/nix-support/propagated-user-env-packages
310− fi
311−
312− ${optionalString (self.enableSharedExecutables && self.isExecutable && self.stdenv.isDarwin) ''
313− for exe in "$out/bin/"* ; do
314− install_name_tool -add_rpath \
315− $out/lib/${ghc.ghc.name}/${self.pname}-${self.version} $exe
316− done
317− ''}
318−
319− eval "$postInstall"
320− '';
321−
322− # We inherit stdenv and ghc so that they can be used
323− # in Cabal derivations.
324− inherit stdenv ghc;
325− };
326− in
327− stdenv.mkDerivation (postprocess (let super = defaults self // args self;
328− self = super // extension self super;
329− in self));
330−}