2008-01-22 17:26:57 +01:00
|
|
|
# generic builder for Cabal packages
|
|
|
|
|
2012-09-06 14:59:07 +02:00
|
|
|
{ stdenv, fetchurl, lib, pkgconfig, ghc, Cabal, jailbreakCabal, enableLibraryProfiling ? false }:
|
2008-01-22 17:26:57 +01:00
|
|
|
{
|
|
|
|
mkDerivation =
|
2011-03-12 18:28:15 +01:00
|
|
|
args : # arguments for the individual package, can modify the defaults
|
2011-08-08 16:12:07 +02:00
|
|
|
let # These attributes are removed in the end. This is in order not to spoil the build
|
|
|
|
# environment overly, but also to keep hash-backwards-compatible with the old cabal.nix.
|
|
|
|
internalAttrs = [
|
|
|
|
"internalAttrs" "buildDepends" "buildTools" "extraLibraries" "pkgconfigDepends"
|
2013-02-24 21:15:25 +01:00
|
|
|
"isLibrary" "isExecutable" "testDepends"
|
2011-08-08 16:12:07 +02:00
|
|
|
];
|
|
|
|
|
2011-08-09 16:55:53 +02:00
|
|
|
# Stuff happening after the user preferences have been processed. We remove
|
|
|
|
# internal attributes and strip null elements from the dependency lists, all
|
|
|
|
# in the interest of keeping hashes stable.
|
|
|
|
postprocess =
|
|
|
|
x : (removeAttrs x internalAttrs) // {
|
|
|
|
buildInputs = stdenv.lib.filter (y : ! (y == null)) x.buildInputs;
|
|
|
|
propagatedBuildInputs = stdenv.lib.filter (y : ! (y == null)) x.propagatedBuildInputs;
|
|
|
|
};
|
|
|
|
|
2011-08-08 16:12:07 +02:00
|
|
|
defaults =
|
2011-03-12 18:28:15 +01:00
|
|
|
self : { # self is the final version of the attribute set
|
2008-01-22 17:26:57 +01:00
|
|
|
|
|
|
|
# pname should be defined by the client to be the package basename
|
|
|
|
# version should be defined by the client to be the package version
|
2010-01-05 16:17:17 +01:00
|
|
|
|
2008-01-22 17:26:57 +01:00
|
|
|
# fname is the internal full name of the package
|
|
|
|
fname = "${self.pname}-${self.version}";
|
|
|
|
|
2010-01-05 16:17:17 +01:00
|
|
|
# name is the external full name of the package; usually we prefix
|
|
|
|
# all packages with haskell- to avoid name clashes for libraries;
|
|
|
|
# if that is not desired (for applications), name can be set to
|
|
|
|
# fname.
|
2011-08-08 16:12:07 +02:00
|
|
|
name = if self.isLibrary then
|
|
|
|
if enableLibraryProfiling then
|
|
|
|
"haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}-profiling"
|
|
|
|
else
|
|
|
|
"haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}"
|
2010-04-27 18:35:01 +02:00
|
|
|
else
|
2011-08-08 16:12:07 +02:00
|
|
|
"${self.pname}-${self.version}";
|
2008-01-22 17:26:57 +01:00
|
|
|
|
|
|
|
# the default download location for Cabal packages is Hackage,
|
|
|
|
# you still have to specify the checksum
|
2010-04-27 18:34:56 +02:00
|
|
|
src = fetchurl {
|
2012-12-15 23:34:49 +01:00
|
|
|
# cannot use mirrors system because of subtly different directory structures
|
|
|
|
urls = ["http://hackage.haskell.org/packages/archive/${self.pname}/${self.version}/${self.fname}.tar.gz"
|
|
|
|
"http://hdiff.luite.com/packages/archive/${self.pname}/${self.fname}.tar.gz"];
|
2008-01-22 17:26:57 +01:00
|
|
|
inherit (self) sha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
# default buildInputs are just ghc, if more buildInputs are required
|
2008-01-22 22:10:19 +01:00
|
|
|
# buildInputs can be extended by the client by using extraBuildInputs,
|
|
|
|
# but often propagatedBuildInputs is preferable anyway
|
2012-02-16 15:05:01 +01:00
|
|
|
buildInputs = [ghc Cabal] ++ self.extraBuildInputs;
|
2011-08-08 16:12:07 +02:00
|
|
|
extraBuildInputs = self.buildTools ++
|
2013-02-24 21:15:25 +01:00
|
|
|
(stdenv.lib.optionals self.doCheck self.testDepends) ++
|
2011-08-08 16:12:07 +02:00
|
|
|
(if self.pkgconfigDepends == [] then [] else [pkgconfig]) ++
|
|
|
|
(if self.isLibrary then [] else self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends);
|
2008-01-22 17:26:57 +01:00
|
|
|
|
|
|
|
# we make sure that propagatedBuildInputs is defined, so that we don't
|
|
|
|
# have to check for its existence
|
2011-08-08 16:12:07 +02:00
|
|
|
propagatedBuildInputs = if self.isLibrary then self.buildDepends ++ self.extraLibraries ++ self.pkgconfigDepends else [];
|
2008-01-22 17:26:57 +01:00
|
|
|
|
|
|
|
# library directories that have to be added to the Cabal files
|
2010-01-04 08:44:32 +01:00
|
|
|
extraLibDirs = [];
|
2008-01-22 17:26:57 +01:00
|
|
|
|
2011-08-08 16:12:07 +02:00
|
|
|
# build-depends Cabal field
|
|
|
|
buildDepends = [];
|
|
|
|
|
2013-02-24 21:15:25 +01:00
|
|
|
# build-depends Cabal fields stated in test-suite stanzas
|
|
|
|
testDepends = [];
|
|
|
|
|
2011-08-08 16:12:07 +02:00
|
|
|
# build-tools Cabal field
|
|
|
|
buildTools = [];
|
|
|
|
|
|
|
|
# extra-libraries Cabal field
|
|
|
|
extraLibraries = [];
|
|
|
|
|
|
|
|
# pkgconfig-depends Cabal field
|
|
|
|
pkgconfigDepends = [];
|
|
|
|
|
|
|
|
isLibrary = ! self.isExecutable;
|
|
|
|
isExecutable = false;
|
|
|
|
|
2013-02-18 12:32:15 +01:00
|
|
|
# ignore version restrictions on the build inputs that the cabal file might specify
|
|
|
|
jailbreak = false;
|
|
|
|
|
|
|
|
# pass the '--enable-split-objs' flag to cabal in the configure stage
|
2013-03-08 13:29:34 +01:00
|
|
|
enableSplitObjs = !stdenv.isDarwin; # http://hackage.haskell.org/trac/ghc/ticket/4013
|
2013-02-18 12:32:15 +01:00
|
|
|
|
2013-02-24 21:15:43 +01:00
|
|
|
# pass the '--enable-tests' flag to cabal in the configure stage
|
|
|
|
# and run any regression test suites the package might have
|
2013-03-23 17:00:11 +01:00
|
|
|
doCheck = stdenv.lib.versionOlder "7.4" ghc.ghcVersion;
|
2013-02-24 21:15:43 +01:00
|
|
|
|
2013-02-24 21:14:01 +01:00
|
|
|
extraConfigureFlags = [
|
|
|
|
(stdenv.lib.enableFeature enableLibraryProfiling "library-profiling")
|
|
|
|
(stdenv.lib.enableFeature self.enableSplitObjs "split-objs")
|
2013-03-11 12:25:53 +01:00
|
|
|
] ++ stdenv.lib.optional (stdenv.lib.versionOlder "7" ghc.ghcVersion) (stdenv.lib.enableFeature self.doCheck "tests");
|
2013-02-18 12:32:15 +01:00
|
|
|
|
2009-04-21 23:05:30 +02:00
|
|
|
# compiles Setup and configures
|
2008-01-22 17:26:57 +01:00
|
|
|
configurePhase = ''
|
|
|
|
eval "$preConfigure"
|
|
|
|
|
2013-02-18 12:32:15 +01:00
|
|
|
${lib.optionalString self.jailbreak "${jailbreakCabal}/bin/jailbreak-cabal ${self.pname}.cabal"}
|
2013-02-24 19:27:08 +01:00
|
|
|
|
2012-09-11 16:53:48 +02:00
|
|
|
for i in Setup.hs Setup.lhs; do
|
2008-01-22 17:26:57 +01:00
|
|
|
test -f $i && ghc --make $i
|
|
|
|
done
|
2010-01-04 08:44:32 +01:00
|
|
|
|
2012-12-28 19:20:09 +01:00
|
|
|
for p in $extraBuildInputs $propagatedNativeBuildInputs; do
|
2010-07-22 20:04:39 +02:00
|
|
|
if [ -d "$p/include" ]; then
|
2013-02-24 21:14:01 +01:00
|
|
|
extraConfigureFlags+=" --extra-include-dir=$p/include"
|
2010-07-22 20:04:39 +02:00
|
|
|
fi
|
2010-01-04 08:44:32 +01:00
|
|
|
for d in lib{,64}; do
|
2010-07-22 20:04:39 +02:00
|
|
|
if [ -d "$p/$d" ]; then
|
2013-02-24 21:14:01 +01:00
|
|
|
extraConfigureFlags+=" --extra-lib-dir=$p/$d"
|
2010-01-04 08:44:32 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2013-02-24 21:14:01 +01:00
|
|
|
echo "configure flags: $extraConfigureFlags $configureFlags"
|
|
|
|
./Setup configure --verbose --prefix="$out" $extraConfigureFlags $configureFlags
|
2008-01-22 17:26:57 +01:00
|
|
|
|
|
|
|
eval "$postConfigure"
|
|
|
|
'';
|
|
|
|
|
|
|
|
# builds via Cabal
|
|
|
|
buildPhase = ''
|
|
|
|
eval "$preBuild"
|
|
|
|
|
|
|
|
./Setup build
|
|
|
|
|
2010-01-05 16:17:17 +01:00
|
|
|
export GHC_PACKAGE_PATH=$(ghc-packages)
|
2011-03-12 18:28:15 +01:00
|
|
|
[ -n "$noHaddock" ] || ./Setup haddock
|
2010-01-05 16:17:17 +01:00
|
|
|
|
2008-01-22 17:26:57 +01:00
|
|
|
eval "$postBuild"
|
|
|
|
'';
|
|
|
|
|
2013-02-24 21:48:36 +01:00
|
|
|
checkPhase = stdenv.lib.optional self.doCheck ''
|
|
|
|
eval "$preCheck"
|
2013-02-24 19:27:08 +01:00
|
|
|
|
2013-02-24 21:48:36 +01:00
|
|
|
./Setup test
|
2013-02-24 19:27:08 +01:00
|
|
|
|
2013-02-24 21:48:36 +01:00
|
|
|
eval "$postCheck"
|
2013-02-24 19:27:08 +01:00
|
|
|
'';
|
|
|
|
|
2010-01-05 16:17:17 +01:00
|
|
|
# installs via Cabal; creates a registration file for nix-support
|
|
|
|
# so that the package can be used in other Haskell-builds; also
|
|
|
|
# adds all propagated build inputs to the user environment packages
|
2008-01-22 17:26:57 +01:00
|
|
|
installPhase = ''
|
|
|
|
eval "$preInstall"
|
|
|
|
|
|
|
|
./Setup copy
|
|
|
|
|
2009-04-25 16:23:00 +02:00
|
|
|
ensureDir $out/bin # necessary to get it added to PATH
|
|
|
|
|
2010-04-27 18:34:56 +02:00
|
|
|
local confDir=$out/lib/ghc-pkgs/ghc-${ghc.ghc.version}
|
2009-04-25 16:23:00 +02:00
|
|
|
local installedPkgConf=$confDir/${self.fname}.installedconf
|
|
|
|
local pkgConf=$confDir/${self.fname}.conf
|
2009-04-18 22:24:36 +02:00
|
|
|
ensureDir $confDir
|
2009-04-25 16:23:00 +02:00
|
|
|
./Setup register --gen-pkg-config=$pkgConf
|
|
|
|
if test -f $pkgConf; then
|
|
|
|
echo '[]' > $installedPkgConf
|
|
|
|
GHC_PACKAGE_PATH=$installedPkgConf ghc-pkg --global register $pkgConf --force
|
|
|
|
fi
|
2009-04-20 16:23:50 +02:00
|
|
|
|
2008-01-22 17:26:57 +01:00
|
|
|
eval "$postInstall"
|
|
|
|
'';
|
2010-01-12 11:18:00 +01:00
|
|
|
|
2010-10-12 09:26:45 +02:00
|
|
|
postFixup = ''
|
2012-12-28 19:20:09 +01:00
|
|
|
if test -f $out/nix-support/propagated-native-build-inputs; then
|
|
|
|
ln -s $out/nix-support/propagated-native-build-inputs $out/nix-support/propagated-user-env-packages
|
2010-10-12 09:26:45 +02:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2010-01-12 11:18:00 +01:00
|
|
|
# We inherit stdenv and ghc so that they can be used
|
|
|
|
# in Cabal derivations.
|
2010-04-27 18:34:56 +02:00
|
|
|
inherit stdenv ghc;
|
2008-01-22 17:26:57 +01:00
|
|
|
};
|
2011-08-09 16:55:53 +02:00
|
|
|
in stdenv.mkDerivation (postprocess ((rec { f = defaults f // args f; }).f)) ;
|
2010-01-05 16:17:17 +01:00
|
|
|
}
|