1{ stdenv, fetchgit, coreutils, cctools, ncurses, libiconv, libX11 }:
2
3stdenv.mkDerivation rec {
4 name = "chez-scheme-${version}";
5 version = "9.5.1";
6
7 src = fetchgit {
8 url = "https://github.com/cisco/chezscheme.git";
9 rev = "bc117fd4d567a6863689fec6814882a0f04e577a";
10 sha256 = "1adzw7bgdz0p4xmccc6awdkb7bp6xba9mnlsh3r3zvblqfci8i70";
11 fetchSubmodules = true;
12 };
13
14 nativeBuildInputs = [ coreutils ] ++ stdenv.lib.optional stdenv.isDarwin cctools;
15 buildInputs = [ ncurses libiconv libX11 ];
16
17 enableParallelBuilding = true;
18
19 /*
20 ** We patch out a very annoying 'feature' in ./configure, which
21 ** tries to use 'git' to update submodules.
22 **
23 ** We have to also fix a few occurrences to tools with absolute
24 ** paths in some helper scripts, otherwise the build will fail on
25 ** NixOS or in any chroot build.
26 */
27 patchPhase = ''
28 substituteInPlace ./configure \
29 --replace "git submodule init && git submodule update || exit 1" "true"
30
31 substituteInPlace ./workarea \
32 --replace "/bin/ln" ln \
33 --replace "/bin/cp" cp
34
35 substituteInPlace ./makefiles/installsh \
36 --replace "/usr/bin/true" "${coreutils}/bin/true"
37
38 substituteInPlace zlib/configure \
39 --replace "/usr/bin/libtool" libtool
40 '';
41
42 /*
43 ** Don't use configureFlags, since that just implicitly appends
44 ** everything onto a --prefix flag, which ./configure gets very angry
45 ** about.
46 **
47 ** Also, carefully set a manual workarea argument, so that we
48 ** can later easily find the machine type that we built Chez
49 ** for.
50 */
51 configurePhase = ''
52 ./configure --threads \
53 --installprefix=$out --installman=$out/share/man \
54 --workarea=work
55 '';
56
57 /*
58 ** Install the kernel.o file, so we can compile C applications that
59 ** link directly to the Chez runtime (for booting their own files, or
60 ** embedding.)
61 **
62 ** Ideally in the future this would be less of a hack and could be
63 ** done by Chez itself. Alternatively, there could just be a big
64 ** case statement matching to the different stdenv.hostPlatform.platform
65 ** values...
66 */
67 postInstall = ''
68 m="$(ls ./work/boot)"
69 if [ "x''${m[1]}" != "x" ]; then
70 >&2 echo "ERROR: more than one bootfile build found; this is a nixpkgs error"
71 exit 1
72 fi
73
74 kernel=./work/boot/$m/kernel.o
75 kerneldest=$out/lib/csv${version}/$m/
76
77 echo installing $kernel to $kerneldest
78 cp $kernel $kerneldest/kernel.o
79 '';
80
81 meta = {
82 description = "A powerful and incredibly fast R6RS Scheme compiler";
83 homepage = https://cisco.github.io/ChezScheme/;
84 license = stdenv.lib.licenses.asl20;
85 platforms = stdenv.lib.platforms.unix;
86 maintainers = with stdenv.lib.maintainers; [ thoughtpolice ];
87 };
88}