nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ pkgs, gccStdenv, lib, coreutils,
2 openssl, zlib, sqlite, libxml2, libyaml, libmysqlclient, lmdb, leveldb, postgresql,
3 version, git-version,
4 gambit-support,
5 gambit ? pkgs.gambit, gambit-params ? pkgs.gambit-support.stable-params, src }:
6
7# We use Gambit, that works 10x better with GCC than Clang. See ../gambit/build.nix
8let stdenv = gccStdenv; in
9
10stdenv.mkDerivation rec {
11 pname = "gerbil";
12 inherit version;
13 inherit src;
14
15 buildInputs_libraries = [ openssl zlib sqlite libxml2 libyaml libmysqlclient lmdb leveldb postgresql ];
16
17 # TODO: either fix all of Gerbil's dependencies to provide static libraries,
18 # or give up and delete all tentative support for static libraries.
19 #buildInputs_staticLibraries = map makeStaticLibraries buildInputs_libraries;
20
21 buildInputs = [ gambit ]
22 ++ buildInputs_libraries; # ++ buildInputs_staticLibraries;
23
24 env.NIX_CFLAGS_COMPILE = "-I${libmysqlclient}/include/mysql -L${libmysqlclient}/lib/mysql";
25
26 postPatch = ''
27 echo '(define (gerbil-version-string) "v${git-version}")' > src/gerbil/runtime/gx-version.scm ;
28 patchShebangs . ;
29 grep -Fl '#!/usr/bin/env' `find . -type f -executable` | while read f ; do
30 substituteInPlace "$f" --replace '#!/usr/bin/env' '#!${coreutils}/bin/env' ;
31 done ;
32'';
33
34## TODO: make static compilation work.
35## For that, get all the packages below to somehow expose static libraries,
36## so we can offer users the option to statically link them into Gambit and/or Gerbil.
37## Then add the following to the postPatch script above:
38# cat > etc/gerbil_static_libraries.sh <<EOF
39# OPENSSL_LIBCRYPTO=${makeStaticLibraries openssl}/lib/libcrypto.a # MISSING!
40# OPENSSL_LIBSSL=${makeStaticLibraries openssl}/lib/libssl.a # MISSING!
41# ZLIB=${makeStaticLibraries zlib}/lib/libz.a
42# SQLITE=${makeStaticLibraries sqlite}/lib/sqlite.a # MISSING!
43# LIBXML2=${makeStaticLibraries libxml2}/lib/libxml2.a # MISSING!
44# YAML=${makeStaticLibraries libyaml}/lib/libyaml.a # MISSING!
45# MYSQL=${makeStaticLibraries libmysqlclient}/lib/mariadb/libmariadb.a
46# LMDB=${makeStaticLibraries lmdb}/lib/mysql/libmysqlclient_r.a # MISSING!
47# LEVELDB=${makeStaticLibraries leveldb}/lib/libleveldb.a
48# EOF
49
50 configurePhase = ''
51 (cd src && ./configure \
52 --prefix=$out/gerbil \
53 --with-gambit=${gambit}/gambit \
54 --enable-libxml \
55 --enable-libyaml \
56 --enable-zlib \
57 --enable-sqlite \
58 --enable-mysql \
59 --enable-lmdb \
60 --enable-leveldb)
61 '';
62
63 buildPhase = ''
64 runHook preBuild
65
66 # gxprof testing uses $HOME/.cache/gerbil/gxc
67 export HOME=$PWD
68 export GERBIL_BUILD_CORES=$NIX_BUILD_CORES
69 export GERBIL_GXC=$PWD/bin/gxc
70 export GERBIL_BASE=$PWD
71 export GERBIL_HOME=$PWD
72 export GERBIL_PATH=$PWD/lib
73 export PATH=$PWD/bin:$PATH
74 ${gambit-support.export-gambopt gambit-params}
75
76 # Build, replacing make by build.sh
77 ( cd src && sh build.sh )
78
79 runHook postBuild
80 '';
81
82 installPhase = ''
83 runHook preInstall
84 mkdir -p $out/gerbil $out/bin
85 (cd src; ./install)
86 (cd $out/bin ; ln -s ../gerbil/bin/* .)
87 runHook postInstall
88 '';
89
90 dontStrip = true;
91
92 meta = {
93 description = "Gerbil Scheme";
94 homepage = "https://github.com/vyzo/gerbil";
95 license = lib.licenses.lgpl21; # also asl20, like Gambit
96 # NB regarding platforms: regularly tested on Linux, only occasionally on macOS.
97 # Please report success and/or failure to fare.
98 platforms = lib.platforms.unix;
99 maintainers = with lib.maintainers; [ fare ];
100 };
101}