1{ lib, stdenv, fetchurl, glib, git,
2 rlwrap, curl, pkg-config, perl, makeWrapper, tzdata, ncurses,
3 pango, cairo, gtk2, gdk-pixbuf, gtkglext,
4 mesa, xorg, openssl, unzip }:
5
6stdenv.mkDerivation rec {
7 pname = "factor-lang";
8 version = "0.98";
9 rev = "7999e72aecc3c5bc4019d43dc4697f49678cc3b4";
10
11 src = fetchurl {
12 url = "https://downloads.factorcode.org/releases/0.98/factor-src-0.98.zip";
13 sha256 = "01ip9mbnar4sv60d2wcwfz62qaamdvbykxw3gbhzqa25z36vi3ri";
14 };
15
16 patches = [
17 ./staging-command-line-0.98-pre.patch
18 ./workdir-0.98-pre.patch
19 ./fuel-dir.patch
20 ];
21
22 nativeBuildInputs = [ makeWrapper unzip ];
23 buildInputs = with xorg; [ git rlwrap curl pkg-config perl
24 libX11 pango cairo gtk2 gdk-pixbuf gtkglext
25 mesa libXmu libXt libICE libSM openssl ];
26
27 buildPhase = ''
28 sed -ie '4i GIT_LABEL = heads/master-${rev}' GNUmakefile
29 make linux-x86-64
30 # De-memoize xdg-* functions, otherwise they break the image.
31 sed -ie 's/^MEMO:/:/' basis/xdg/xdg.factor
32 '';
33
34 installPhase = ''
35 mkdir -p $out/bin $out/lib/factor
36 # The released image has library path info embedded, so we
37 # first have to recreate the boot image with Nix paths, and
38 # then use it to build the Nix release image.
39 cp boot.unix-x86.64.image $out/lib/factor/factor.image
40
41 cp -r basis core extra $out/lib/factor
42
43 # Factor uses XDG_CACHE_HOME for cache during compilation.
44 # We can't have that. So set it to $TMPDIR/.cache
45 export XDG_CACHE_HOME=$TMPDIR/.cache && mkdir -p $XDG_CACHE_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 ${lib.makeLibraryPath (with xorg; [
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 "${lib.makeLibraryPath (with xorg; [ glib
73 libX11 pango cairo gtk2 gdk-pixbuf gtkglext
74 mesa libXmu libXt libICE libSM openssl])}"
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 # build full factor image from boot image
80 (cd $out/bin && ./factor -script -e='"unix-x86.64" USING: system bootstrap.image memory ; make-image save 0 exit' )
81
82 # make a new bootstrap image
83 (cd $out/bin && ./factor -script -e='"unix-x86.64" USING: system tools.deploy.backend ; make-boot-image 0 exit' )
84
85 # rebuild final full factor image to include all patched sources
86 (cd $out/lib/factor && ./factor -i=boot.unix-x86.64.image)
87
88 # install fuel mode for emacs
89 mkdir -p $out/share/emacs/site-lisp
90 # update default paths in factor-listener.el for fuel mode
91 substituteInPlace misc/fuel/fuel-listener.el \
92 --subst-var-by fuel_factor_root_dir $out/lib/factor \
93 --subst-var-by fuel_listener_factor_binary $out/bin/factor
94 cp misc/fuel/*.el $out/share/emacs/site-lisp/
95 '';
96
97 meta = with lib; {
98 homepage = "https://factorcode.org";
99 license = licenses.bsd2;
100 description = "A concatenative, stack-based programming language";
101
102 maintainers = [ maintainers.vrthra maintainers.spacefrogg ];
103 platforms = [ "x86_64-linux" ];
104 };
105}