1{ stdenv, fetchurl, fetchFromGitHub, glib, glibc, git,
2 rlwrap, curl, pkgconfig, perl, makeWrapper, tzdata, ncurses,
3 libX11, pango, cairo, gtk2, gdk_pixbuf, gtkglext,
4 mesa, libXmu, libXt, libICE, libSM }:
5
6stdenv.mkDerivation rec {
7 name = "factor-lang-${version}";
8 version = "0.97";
9 rev = "eb3ca179740e6cfba696b55a999caa13369e6182";
10
11 src = fetchFromGitHub {
12 owner = "factor";
13 repo = "factor";
14 rev = rev;
15 sha256 = "16zlbxbad3d19jq01nk824i19bypqzn8l3yfxys40z06vjjncapd";
16 };
17
18 factorimage = fetchurl {
19 url = http://downloads.factorcode.org/releases/0.97/factor-linux-x86-64-0.97.tar.gz;
20 sha256 = "06y125c8vbng54my5fxdr3crpxkvhhcng2n35cxddd3wcg6vhxhp";
21 name = "factorimage";
22 };
23
24 buildInputs = [ git rlwrap curl pkgconfig perl makeWrapper
25 libX11 pango cairo gtk2 gdk_pixbuf gtkglext
26 mesa libXmu libXt libICE libSM ];
27
28 buildPhase = ''
29 make $(bash ./build-support/factor.sh make-target) GIT_LABEL=heads/master-${rev}
30 '';
31
32 installPhase = ''
33 mkdir -p $out/bin $out/lib/factor
34 # First, get a workable image. Unfortunately, no boot-image
35 # is available with release info. So fetch a released image.
36 # The released image has library path info embedded, so we
37 # have to first recreate the boot image with Nix paths, and
38 # then use it to build the Nix release image.
39 zcat ${factorimage} | (cd $out/lib && tar -xvpf - factor/factor.image )
40
41 cp -r basis core extra unmaintained $out/lib/factor
42
43 # Factor uses the home directory for cache during compilation.
44 # We cant have that. So set it to $TMPDIR/.home
45 export HOME=$TMPDIR/.home && mkdir -p $HOME
46
47 # there is no ld.so.cache in NixOS so we construct one
48 # out of known libraries. The side effect is that find-lib
49 # will work only on the known libraries. There does not seem
50 # to be a generic solution here.
51 find $(echo ${stdenv.lib.makeLibraryPath [
52 glib libX11 pango cairo gtk2 gdk_pixbuf gtkglext
53 mesa libXmu libXt libICE libSM ]} | sed -e 's#:# #g') -name \*.so.\* > $TMPDIR/so.lst
54
55 (echo $(cat $TMPDIR/so.lst | wc -l) "libs found in cache \`/etc/ld.so.cache'";
56 for l in $(<$TMPDIR/so.lst);
57 do
58 echo " $(basename $l) (libc6,x86-64) => $l";
59 done)> $out/lib/factor/ld.so.cache
60
61 sed -ie "s#/sbin/ldconfig -p#cat $out/lib/factor/ld.so.cache#g" \
62 $out/lib/factor/basis/alien/libraries/finder/linux/linux.factor
63
64 sed -ie 's#/usr/share/zoneinfo/#${tzdata}/share/zoneinfo/#g' \
65 $out/lib/factor/extra/tzinfo/tzinfo.factor
66
67 sed -ie 's#/usr/share/terminfo#${ncurses.out}/share/terminfo#g' \
68 $out/lib/factor/extra/terminfo/terminfo.factor
69
70 cp ./factor $out/bin
71 wrapProgram $out/bin/factor --prefix LD_LIBRARY_PATH : \
72 "${stdenv.lib.makeLibraryPath [ glib
73 libX11 pango cairo gtk2 gdk_pixbuf gtkglext
74 mesa libXmu libXt libICE libSM ]}"
75
76 sed -ie 's#/bin/.factor-wrapped#/lib/factor/factor#g' $out/bin/factor
77 mv $out/bin/.factor-wrapped $out/lib/factor/factor
78
79 # make a new bootstrap image
80 (cd $out/bin && ./factor -script -e='"unix-x86.64" USING: system bootstrap.image memory ; make-image save 0 exit' )
81 mv $out/lib/factor/boot.unix-x86.64.image $out/lib/factor/factor.image
82 # now make the full system image, it overwrites $out/lib/factor/factor.image
83 $out/bin/factor -i=$out/lib/factor/factor.image
84 '';
85
86 meta = with stdenv.lib; {
87 homepage = http://factorcode.org;
88 license = licenses.bsd2;
89 description = "A concatenative, stack-based programming language";
90
91 maintainers = [ maintainers.vrthra ];
92 platforms = [ "x86_64-linux" ];
93 };
94}