* added generic Cabal builder

* transformed zlib, vty, binary, X11 to use generic Cabal builder
* note that Cabal library packages are now by default prefixed with "haskell-"

svn path=/nixpkgs/trunk/; revision=10247
This commit is contained in:
Andres Löh 2008-01-22 16:26:57 +00:00
parent dffda95fdd
commit d8694e68eb
6 changed files with 118 additions and 152 deletions

View File

@ -1,49 +1,13 @@
{stdenv, fetchurl, ghc, libX11, xineramaSupport ? true, libXinerama ? null, libXext ? null}:
{cabal, libX11, xineramaSupport ? true, libXinerama ? null, libXext ? null}:
assert xineramaSupport -> (libXinerama != null && libXext != null);
stdenv.mkDerivation (rec {
cabal.mkDerivation (self : {
pname = "X11";
version = "1.4.1";
name = "${pname}-${version}";
src = fetchurl {
url = "http://hackage.haskell.org/packages/archive/${pname}/${version}/${name}.tar.gz";
sha256 = "e51038541415686f0e278ccdbc0b2373cd11f212de99023b7b8f8e776aa09f79";
};
buildInputs = [ghc];
propagatedBuildInputs = [libX11] ++
(if xineramaSupport then [libXinerama libXext] else []);
sha256 = "e51038541415686f0e278ccdbc0b2373cd11f212de99023b7b8f8e776aa09f79";
propagatedBuildInputs = [libX11] ++ (if xineramaSupport then [libXinerama libXext] else []);
meta = {
description = "A Haskell binding to the X11 graphics library";
};
extraLibDirs = "${libX11}/lib" + (if xineramaSupport then " ${libXinerama}/lib ${libXext}/lib" else "");
configurePhase = ''
echo "extra-lib-dirs: ${extraLibDirs}" >> X11.buildinfo.in
ghc --make Setup.hs
./Setup configure --prefix="$out"
'';
buildPhase = ''
./Setup build
'';
installPhase = ''
./Setup copy
./Setup register --gen-script
mkdir $out/nix-support
sed -i 's/|.*\(ghc-pkg update\)/| \1/' register.sh
cp register.sh $out/nix-support/register-ghclib.sh
sed -i 's/\(ghc-pkg update\)/\1 --user/' register.sh
mkdir $out/bin
cp register.sh $out/bin/register-ghclib-${name}.sh
'';
})

View File

@ -1,41 +1,11 @@
{stdenv, fetchurl, ghc}:
stdenv.mkDerivation (rec {
{cabal}:
cabal.mkDerivation (self : {
pname = "binary";
version = "0.4.1";
name = "${pname}-${version}";
src = fetchurl {
url = "http://hackage.haskell.org/packages/archive/${pname}/${version}/${pname}-${version}.tar.gz";
sha256 = "bb74824306843da25f6d97c271e2a06ee3a7e05fc529156fb81d7c576688e549";
};
buildInputs = [ghc];
sha256 = "bb74824306843da25f6d97c271e2a06ee3a7e05fc529156fb81d7c576688e549";
meta = {
description = "Efficient, pure binary serialisation using lazy ByteStrings";
};
})
configurePhase = ''
ghc --make Setup.lhs
./Setup configure --prefix="$out"
'';
buildPhase = ''
./Setup build
'';
installPhase = ''
./Setup copy
./Setup register --gen-script
mkdir $out/nix-support
sed -i 's/|.*\(ghc-pkg update\)/| \1/' register.sh
cp register.sh $out/nix-support/register-ghclib.sh
sed -i 's/\(ghc-pkg update\)/\1 --user/' register.sh
mkdir $out/bin
cp register.sh $out/bin/register-ghclib-${name}.sh
'';
})

View File

@ -0,0 +1,92 @@
# generic builder for Cabal packages
attrs :
{
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
# 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 = "haskell-${self.fname}";
# the default download location for Cabal packages is Hackage,
# you still have to specify the checksum
src = attrs.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, but often propagatedBuildInputs
# is preferable anyway
buildInputs = [attrs.ghc];
# 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 = map (x : x + "/lib") self.propagatedBuildInputs;
# file(s) that have to be patched with information about extra libraries;
# can be redefined to the empty list by the client if this is not desired
patchLibFiles = [ "${self.pname}.cabal" ];
# patches files, compiles Setup, and configures
configurePhase = ''
eval "$preConfigure"
for i in ${toString self.patchLibFiles}; do
echo "patching $i"
test -f $i && sed -i '/extra-libraries/ { s|\( *\)extra-libraries.*|&\n\1extra-lib-dirs: ${toString self.extraLibDirs}| }' $i
done
for i in Setup.hs Setup.lhs; do
test -f $i && ghc --make $i
done
./Setup configure --prefix="$out"
eval "$postConfigure"
'';
# builds via Cabal
buildPhase = ''
eval "$preBuild"
./Setup build
eval "$postBuild"
'';
# installs via Cabal; creates a registration file for nix-support
# so that the package can be used in other Haskell-builds; also
# creates a register-${name}.sh in userspace that can be used to
# register the library in a user environment (but this scheme
# should sooner or later be deprecated in favour of using a
# ghc-wrapper).
installPhase = ''
eval "$preInstall"
./Setup copy
./Setup register --gen-script
mkdir $out/nix-support
sed -i 's/|.*\(ghc-pkg update\)/| \1/' register.sh
cp register.sh $out/nix-support/register-ghclib.sh
sed -i 's/\(ghc-pkg update\)/\1 --user/' register.sh
mkdir $out/bin
cp register.sh $out/bin/register-${self.name}.sh
eval "$postInstall"
'';
};
in attrs.stdenv.mkDerivation ((rec { f = dtransform f // transform f; }).f);
}

View File

@ -1,42 +1,13 @@
{stdenv, fetchurl, ghc}:
stdenv.mkDerivation (rec {
{cabal}:
cabal.mkDerivation (self : {
pname = "vty";
version = "3.0.0";
name = "${pname}-${version}";
src = fetchurl {
url = "http://hackage.haskell.org/packages/archive/${pname}/${version}/${name}.tar.gz";
sha256 = "44ae53d06b8b45c14cd3861e860a38730ed9995ed56b1b3d9aba6641771f1947";
};
buildInputs = [ghc];
sha256 = "44ae53d06b8b45c14cd3861e860a38730ed9995ed56b1b3d9aba6641771f1947";
meta = {
description = "vty is a *very* simplistic library in the niche of ncurses";
};
configurePhase = ''
sed -i 's|^Build-Depends:.*$|&, bytestring, containers|' ${pname}.cabal
ghc --make Setup.lhs
./Setup configure -v --prefix="$out"
preConfigure = ''
sed -i 's|^Build-Depends:.*$|&, bytestring, containers|' ${self.pname}.cabal
'';
buildPhase = ''
./Setup build
'';
installPhase = ''
./Setup copy
./Setup register --gen-script
mkdir $out/nix-support
sed -i 's/|.*\(ghc-pkg update\)/| \1/' register.sh
cp register.sh $out/nix-support/register-ghclib.sh
sed -i 's/\(ghc-pkg update\)/\1 --user/' register.sh
mkdir $out/bin
cp register.sh $out/bin/register-ghclib-${name}.sh
'';
})

View File

@ -1,46 +1,11 @@
{stdenv, fetchurl, ghc, zlib}:
stdenv.mkDerivation (rec {
{cabal, zlib}:
cabal.mkDerivation (self : {
pname = "zlib";
version = "0.4.0.2";
name = "${pname}-Haskell-${version}";
src = fetchurl {
url = "http://hackage.haskell.org/packages/archive/${pname}/${version}/${pname}-${version}.tar.gz";
sha256 = "e6e9e51ca5b7f1685eb031f826f7865acc10cc2c8d0dfad975e0e81fd17f17ed";
};
buildInputs = [ghc];
sha256 = "e6e9e51ca5b7f1685eb031f826f7865acc10cc2c8d0dfad975e0e81fd17f17ed";
propagatedBuildInputs = [zlib];
meta = {
description = "Compression and decompression in the gzip and zlib formats";
};
extraLibDirs = "${zlib}/lib";
configurePhase = ''
sed -i '/extra-libraries/a\ \ \ \ extra-lib-dirs: ${extraLibDirs}' ${pname}.cabal
ghc --make Setup.hs
./Setup configure --prefix="$out"
'';
buildPhase = ''
./Setup build
'';
installPhase = ''
./Setup copy
./Setup register --gen-script
mkdir $out/nix-support
sed -i 's/|.*\(ghc-pkg update\)/| \1/' register.sh
cp register.sh $out/nix-support/register-ghclib.sh
sed -i 's/\(ghc-pkg update\)/\1 --user/' register.sh
mkdir $out/bin
cp register.sh $out/bin/register-ghclib-${name}.sh
'';
})

View File

@ -2638,6 +2638,12 @@ rec {
### DEVELOPMENT / LIBRARIES / HASKELL
binary = import ../development/libraries/haskell/binary {
cabal = cabal68;
};
# cabal is a utility function to build cabal-based
# Haskell packages
cabal68 = import ../development/libraries/haskell/cabal/cabal.nix {
inherit stdenv fetchurl;
ghc = ghc68;
};
@ -2667,20 +2673,18 @@ rec {
# }));
X11 = import ../development/libraries/haskell/X11 {
inherit stdenv fetchurl;
ghc = ghc68;
inherit (xlibs) libX11 libXinerama libXext;
xineramaSupport = true;
cabal = cabal68;
};
vty = import ../development/libraries/haskell/vty {
inherit stdenv fetchurl;
ghc = ghc68;
cabal = cabal68;
};
zlibHaskell = import ../development/libraries/haskell/zlib {
inherit stdenv fetchurl zlib;
ghc = ghc68;
inherit zlib;
cabal = cabal68;
};
### DEVELOPMENT / PERL MODULES