nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 makeWrapper,
5 buildEnv,
6 copyDesktopItems,
7 makeDesktopItem,
8 factor-unwrapped,
9 cairo,
10 freealut,
11 gdk-pixbuf,
12 glib,
13 gnome2,
14 gtk2-x11,
15 libGL,
16 libGLU,
17 librsvg,
18 graphviz,
19 libogg,
20 libvorbis,
21 openal,
22 openssl,
23 pango,
24 pcre,
25 udis86,
26 zlib,
27 # Enable factor GUI support
28 guiSupport ? true,
29 # Libraries added to ld.so.cache
30 extraLibs ? [ ],
31 # Packages added to path (and ld.so.cache)
32 binPackages ? [ ],
33 # Extra vocabularies added to out/lib/factor
34 extraVocabs ? [ ],
35 # Enable default libs and bins to run most of the standard library code.
36 enableDefaults ? true,
37 doInstallCheck ? true,
38}:
39let
40 inherit (lib)
41 optional
42 optionals
43 optionalString
44 versionOlder
45 versionAtLeast
46 ;
47 # missing from lib/strings
48 escapeNixString = s: lib.escape [ "$" ] (builtins.toJSON s);
49 toFactorArgs = x: lib.concatStringsSep " " (map escapeNixString x);
50 defaultLibs = optionals enableDefaults [
51 libogg
52 libvorbis
53 openal
54 openssl
55 pcre
56 udis86
57 zlib
58 ];
59 defaultBins = optionals enableDefaults [ graphviz ];
60 runtimeLibs =
61 defaultLibs
62 ++ extraLibs
63 ++ binPackages
64 ++ (lib.flatten (map (v: v.extraLibs or [ ]) extraVocabs))
65 ++ optionals guiSupport [
66 cairo
67 freealut
68 gdk-pixbuf
69 glib
70 gnome2.gtkglext
71 gtk2-x11
72 libGL
73 libGLU
74 pango
75 ];
76 bins = binPackages ++ defaultBins ++ (lib.flatten (map (v: v.extraPaths or [ ]) extraVocabs));
77 vocabTree = buildEnv {
78 name = "${factor-unwrapped.pname}-vocabs";
79 ignoreCollisions = true;
80 pathsToLink = map (r: "/lib/factor/${r}") [
81 "basis"
82 "core"
83 "extra"
84 ];
85 paths = [ factor-unwrapped ] ++ extraVocabs;
86 };
87
88in
89stdenv.mkDerivation (finalAttrs: {
90 pname = "${factor-unwrapped.pname}-env";
91 inherit (factor-unwrapped) version;
92
93 nativeBuildInputs = [
94 copyDesktopItems
95 makeWrapper
96 ];
97 buildInputs = optional guiSupport gdk-pixbuf;
98
99 dontUnpack = true;
100
101 desktopItems = [
102 (makeDesktopItem {
103 name = "Factor";
104 desktopName = "Factor";
105 comment = "A practical stack language";
106 exec = "factor";
107 icon = "factor";
108 categories = [
109 "Development"
110 "IDE"
111 ];
112 })
113 ];
114
115 installPhase = ''
116 runHook preInstall
117 ''
118 + optionalString guiSupport (
119 ''
120 # Set Gdk pixbuf loaders file to the one from the build dependencies here
121 unset GDK_PIXBUF_MODULE_FILE
122 # Defined in gdk-pixbuf setup hook
123 findGdkPixbufLoaders "${librsvg}"
124 makeWrapperArgs+=(--set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE")
125 ''
126 + optionalString (versionAtLeast finalAttrs.version "0.101") ''
127 mkdir -p $out/share/applications $out/share/icons/hicolor/scalable/apps
128 cp ${factor-unwrapped}/lib/factor/misc/icons/icon.svg $out/share/icons/hicolor/scalable/apps/factor.svg
129 cp ${factor-unwrapped}/lib/factor/misc/icons/icon.ico $out/share/icons/hicolor/scalable/apps/factor.ico
130 for i in 16 32 48 64 128 256 512; do
131 mkdir -p $out/share/icons/hicolor/''${i}x''${i}/apps
132 cp ${factor-unwrapped}/lib/factor/misc/icons/icon_''${i}x''${i}.png $out/share/icons/hicolor/''${i}x''${i}/apps/factor.png
133 done
134 ''
135 )
136 + ''
137 makeWrapperArgs+=(
138 --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:${lib.makeLibraryPath runtimeLibs}
139 --prefix PATH : ${lib.makeBinPath bins})
140 mkdir -p "$out/bin"
141 cp -r "${factor-unwrapped}/lib" "$out/"
142 chmod -R u+w "$out/lib"
143 rm -rf "$out/lib/factor/misc"
144 (
145 cd ${vocabTree}
146 for f in "lib/factor/"* ; do
147 rm -r "$out/$f"
148 cp -rL "${vocabTree}/$f" "$out/$f"
149 done
150 )
151
152 # There is no ld.so.cache in NixOS so we construct one
153 # out of known libraries. The side effect is that find-lib
154 # will work only on the known libraries. There does not seem
155 # to be a generic solution here.
156 find $(echo ${
157 lib.makeLibraryPath ([ stdenv.cc.libc ] ++ runtimeLibs)
158 } | sed -e 's#:# #g') -name \*.so.\* > $TMPDIR/so.lst
159 (echo $(cat $TMPDIR/so.lst | wc -l) "libs found in cache \`/etc/ld.so.cache'";
160 for l in $(<$TMPDIR/so.lst); do
161 echo " $(basename $l) (libc6,x86-64) => $l";
162 done)> $out/lib/factor/ld.so.cache
163
164 # Create a wrapper in bin/ and lib/factor/
165 wrapProgram "$out/lib/factor/factor" \
166 --argv0 factor \
167 --set FACTOR_LD_SO_CACHE "$out/lib/factor/ld.so.cache" \
168 "''${makeWrapperArgs[@]}"
169 mv $out/lib/factor/factor.image $out/lib/factor/.factor-wrapped.image
170 cp $out/lib/factor/factor $out/bin/
171
172 # Emacs fuel expects the image being named `factor.image` in the factor base dir
173 ln -rs $out/lib/factor/.factor-wrapped.image $out/lib/factor/factor.image
174
175 ''
176 + optionalString (versionOlder finalAttrs.version "0.101") ''
177 mkdir -p "$out/share/emacs/site-lisp"
178 cp -r "${factor-unwrapped}/lib/factor/misc/fuel/"*.el "$out/share/emacs/site-lisp"
179 chmod -R u+wr "$out/share/emacs"
180 # Update default paths in fuel-listener.el to new output
181 sed -E -i -e 's#(\(defcustom fuel-factor-root-dir ").*(")#'"\1$out/lib/factor\2#" \
182 "$out/share/emacs/site-lisp/fuel-listener.el"
183 ''
184 + ''
185 runHook postInstall
186 '';
187
188 inherit doInstallCheck;
189 disabledTests = toFactorArgs [
190 "io.files.info.unix"
191 "io.launcher.unix"
192 "io.ports"
193 "io.sockets"
194 "io.sockets.unix"
195 "io.sockets.secure.openssl"
196 "io.sockets.secure.unix"
197 ];
198 installCheckPhase = ''
199 runHook preInstallCheck
200
201 export HOME=$TMPDIR
202 $out/bin/factor -e='USING: tools.test tools.test.private
203 zealot.factor sequences namespaces formatting ;
204 zealot-core-vocabs
205 { ${finalAttrs.disabledTests} } without
206 "compiler" suffix
207 [ test-vocab ] each :test-failures
208 test-failures get length "Number of failed tests: %d\n" printf'
209
210 runHook postInstallCheck
211 '';
212
213 passthru = {
214 inherit
215 defaultLibs
216 defaultBins
217 extraLibs
218 runtimeLibs
219 binPackages
220 extraVocabs
221 vocabTree
222 ;
223 };
224
225 meta = factor-unwrapped.meta // {
226 mainProgram = "factor";
227 };
228})