1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/pkgs/development/libraries/haskell/cabal/cabal.nix
Andres Löh 3e0ac9b040 Major Haskell packages overhaul.
Several changes, some highlights:

  * Structure of haskell-packages.nix updated. It's now easier to
    select different default versions of packages for different
    versions of GHC.

  * GHC 7.0.2 is now default.

  * Haskell Platform 2011.2.0.0 has been added and is now default.

  * Several packages have been updated
    (gtk2hs, gitit, xmonad, darcs, ...).

  * Some old packages have been removed.

svn path=/nixpkgs/trunk/; revision=26288
2011-03-12 17:28:15 +00:00

120 lines
4.6 KiB
Nix

# generic builder for Cabal packages
{stdenv, fetchurl, lib, ghc, enableLibraryProfiling ? false} :
{
mkDerivation =
args : # arguments for the individual package, can modify the defaults
let defaults =
self : { # self is the final version of the attribute set
# pname should be defined by the client to be the package basename
# version should be defined by the client to be the package version
# fname is the internal full name of the package
fname = "${self.pname}-${self.version}";
# 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.
name = if enableLibraryProfiling then
"haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}-profiling"
else
"haskell-${self.pname}-ghc${ghc.ghc.version}-${self.version}";
# the default download location for Cabal packages is Hackage,
# you still have to specify the checksum
src = fetchurl {
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
# buildInputs can be extended by the client by using extraBuildInputs,
# but often propagatedBuildInputs is preferable anyway
buildInputs = [ghc] ++ self.extraBuildInputs;
extraBuildInputs = [];
# 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
extraLibDirs = [];
libraryProfiling =
if enableLibraryProfiling then ["--enable-library-profiling"]
else ["--disable-library-profiling"];
# compiles Setup and configures
configurePhase = ''
eval "$preConfigure"
for i in Setup.hs Setup.lhs; do
test -f $i && ghc --make $i
done
for p in $extraBuildInputs $propagatedBuildNativeInputs; do
if [ -d "$p/include" ]; then
extraLibDirs="$extraLibDirs --extra-include-dir=$p/include"
fi
for d in lib{,64}; do
if [ -d "$p/$d" ]; then
extraLibDirs="$extraLibDirs --extra-lib-dir=$p/$d"
fi
done
done
./Setup configure --verbose --prefix="$out" $libraryProfiling $extraLibDirs $configureFlags
eval "$postConfigure"
'';
# builds via Cabal
buildPhase = ''
eval "$preBuild"
./Setup build
export GHC_PACKAGE_PATH=$(ghc-packages)
[ -n "$noHaddock" ] || ./Setup haddock
eval "$postBuild"
'';
# 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
installPhase = ''
eval "$preInstall"
./Setup copy
ensureDir $out/bin # necessary to get it added to PATH
local confDir=$out/lib/ghc-pkgs/ghc-${ghc.ghc.version}
local installedPkgConf=$confDir/${self.fname}.installedconf
local pkgConf=$confDir/${self.fname}.conf
ensureDir $confDir
./Setup register --gen-pkg-config=$pkgConf
if test -f $pkgConf; then
echo '[]' > $installedPkgConf
GHC_PACKAGE_PATH=$installedPkgConf ghc-pkg --global register $pkgConf --force
fi
eval "$postInstall"
'';
postFixup = ''
if test -f $out/nix-support/propagated-build-native-inputs; then
ln -s $out/nix-support/propagated-build-native-inputs $out/nix-support/propagated-user-env-packages
fi
'';
# We inherit stdenv and ghc so that they can be used
# in Cabal derivations.
inherit stdenv ghc;
};
in stdenv.mkDerivation ((rec { f = defaults f // args f; }).f);
}