2008-01-22 16:26:57 +00:00
|
|
|
# generic builder for Cabal packages
|
|
|
|
|
2010-04-27 19:21:07 +01:00
|
|
|
{stdenv, fetchurl, lib, ghc, enableLibraryProfiling ? false} :
|
2008-01-22 16:26:57 +00:00
|
|
|
{
|
|
|
|
mkDerivation =
|
|
|
|
transform :
|
|
|
|
let dtransform =
|
|
|
|
self : {
|
|
|
|
|
|
|
|
# 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 15:17:17 +00:00
|
|
|
|
2008-01-22 16:26:57 +00:00
|
|
|
# fname is the internal full name of the package
|
|
|
|
fname = "${self.pname}-${self.version}";
|
|
|
|
|
2010-01-05 15:17:17 +00: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.
|
2010-04-27 17:35:01 +01:00
|
|
|
name = if enableLibraryProfiling then
|
2010-04-27 19:21:07 +01:00
|
|
|
"haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}-profiling"
|
2010-04-27 17:35:01 +01:00
|
|
|
else
|
|
|
|
"haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}";
|
2008-01-22 16:26:57 +00:00
|
|
|
|
|
|
|
# the default download location for Cabal packages is Hackage,
|
|
|
|
# you still have to specify the checksum
|
2010-04-27 17:34:56 +01:00
|
|
|
src = fetchurl {
|
2008-01-22 16:26:57 +00:00
|
|
|
url = "http://hackage.haskell.org/packages/archive/${self.pname}/${self.version}/${self.fname}.tar.gz";
|
|
|
|
inherit (self) sha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
# default buildInputs are just ghc, if more buildInputs are required
|
2008-01-22 21:10:19 +00:00
|
|
|
# buildInputs can be extended by the client by using extraBuildInputs,
|
|
|
|
# but often propagatedBuildInputs is preferable anyway
|
2010-04-27 17:34:56 +01:00
|
|
|
buildInputs = [ghc] ++ self.extraBuildInputs;
|
2008-01-22 21:10:19 +00:00
|
|
|
extraBuildInputs = [];
|
2008-01-22 16:26:57 +00:00
|
|
|
|
|
|
|
# we make sure that propagatedBuildInputs is defined, so that we don't
|
|
|
|
# have to check for its existence
|
|
|
|
propagatedBuildInputs = [];
|
|
|
|
|
|
|
|
# library directories that have to be added to the Cabal files
|
2010-01-04 07:44:32 +00:00
|
|
|
extraLibDirs = [];
|
2008-01-22 16:26:57 +00:00
|
|
|
|
2010-04-27 17:34:56 +01:00
|
|
|
libraryProfiling =
|
|
|
|
if enableLibraryProfiling then ["--enable-library-profiling"]
|
|
|
|
else ["--disable-library-profiling"];
|
|
|
|
|
2009-04-21 22:05:30 +01:00
|
|
|
# compiles Setup and configures
|
2008-01-22 16:26:57 +00:00
|
|
|
configurePhase = ''
|
|
|
|
eval "$preConfigure"
|
|
|
|
|
|
|
|
for i in Setup.hs Setup.lhs; do
|
|
|
|
test -f $i && ghc --make $i
|
|
|
|
done
|
2010-01-04 07:44:32 +00:00
|
|
|
|
2010-02-18 01:49:50 +00:00
|
|
|
for p in $propagatedBuildNativeInputs; do
|
2010-01-04 07:44:32 +00:00
|
|
|
for d in lib{,64}; do
|
|
|
|
if [ -e "$p/$d" ]; then
|
|
|
|
extraLibDirs="$extraLibDirs --extra-lib-dir=$p/$d"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2010-04-27 17:34:56 +01:00
|
|
|
./Setup configure --verbose --prefix="$out" $libraryProfiling $extraLibDirs $configureFlags
|
2008-01-22 16:26:57 +00:00
|
|
|
|
|
|
|
eval "$postConfigure"
|
|
|
|
'';
|
|
|
|
|
|
|
|
# builds via Cabal
|
|
|
|
buildPhase = ''
|
|
|
|
eval "$preBuild"
|
|
|
|
|
|
|
|
./Setup build
|
|
|
|
|
2010-01-05 15:17:17 +00:00
|
|
|
export GHC_PACKAGE_PATH=$(ghc-packages)
|
2010-01-24 15:39:46 +00:00
|
|
|
[ -n "$noHadock" ] || ./Setup haddock
|
2010-01-05 15:17:17 +00:00
|
|
|
|
2008-01-22 16:26:57 +00:00
|
|
|
eval "$postBuild"
|
|
|
|
'';
|
|
|
|
|
2010-01-05 15:17:17 +00: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 16:26:57 +00:00
|
|
|
installPhase = ''
|
|
|
|
eval "$preInstall"
|
|
|
|
|
|
|
|
./Setup copy
|
|
|
|
|
2009-04-25 15:23:00 +01:00
|
|
|
ensureDir $out/bin # necessary to get it added to PATH
|
|
|
|
|
2010-04-27 17:34:56 +01:00
|
|
|
local confDir=$out/lib/ghc-pkgs/ghc-${ghc.ghc.version}
|
2009-04-25 15:23:00 +01:00
|
|
|
local installedPkgConf=$confDir/${self.fname}.installedconf
|
|
|
|
local pkgConf=$confDir/${self.fname}.conf
|
2009-04-18 21:24:36 +01:00
|
|
|
ensureDir $confDir
|
2009-04-25 15:23:00 +01: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 15:23:50 +01:00
|
|
|
|
|
|
|
ensureDir $out/nix-support
|
2010-04-01 11:56:50 +01:00
|
|
|
ln -s $out/nix-support/propagated-build-native-inputs $out/nix-support/propagated-user-env-packages
|
2010-01-05 15:17:17 +00:00
|
|
|
|
2008-01-22 16:26:57 +00:00
|
|
|
eval "$postInstall"
|
|
|
|
'';
|
2010-01-12 10:18:00 +00:00
|
|
|
|
|
|
|
# We inherit stdenv and ghc so that they can be used
|
|
|
|
# in Cabal derivations.
|
2010-04-27 17:34:56 +01:00
|
|
|
inherit stdenv ghc;
|
2008-01-22 16:26:57 +00:00
|
|
|
};
|
2010-04-27 17:34:56 +01:00
|
|
|
in stdenv.mkDerivation ((rec { f = dtransform f // transform f; }).f);
|
2010-01-05 15:17:17 +00:00
|
|
|
}
|