-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
/
generic.nix
428 lines (396 loc) · 11.6 KB
/
generic.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
{ pname ? "emacs"
, version
, versionModifier ? ""
, name ? "emacs-${version}${versionModifier}"
, variant
, src
, patches ? _: [ ]
}:
{ lib
, stdenv
, Xaw3d
, acl
, alsa-lib
, autoreconfHook
, cairo
, dbus
, emacsPackagesFor
, fetchpatch
, gconf
, gettext
, giflib
, glib-networking
, gnutls
, gpm
, gsettings-desktop-schemas
, gtk2-x11
, gtk3
, gtk3-x11
, harfbuzz
, imagemagick
, jansson
, libXaw
, libXcursor
, libXft
, libXpm
, libgccjit
, libjpeg
, libotf
, libpng
, librsvg
, libselinux
, libtiff
, libwebp
, libxml2
, llvmPackages_6
, m17n_lib
, makeWrapper
, motif
, ncurses
, nixosTests
, pkg-config
, recurseIntoAttrs
, sigtool
, sqlite
, substituteAll
, systemd
, tree-sitter
, texinfo
, webkitgtk
, wrapGAppsHook
# macOS dependencies for NS and macPort
, AppKit
, Carbon
, Cocoa
, GSS
, IOKit
, ImageCaptureCore
, ImageIO
, OSAKit
, Quartz
, QuartzCore
, WebKit
# Boolean flags
, nativeComp ? true
, noGui ? false
, srcRepo ? true
, withAcl ? false
, withAlsaLib ? false
, withAthena ? false
, withCsrc ? true
, withGTK2 ? false
, withGTK3 ? withPgtk && !noGui
, withGconf ? false
, withGpm ? stdenv.isLinux
, withImageMagick ? lib.versionOlder version "27" && (withX || withNS)
, withMotif ? false
, withNS ? stdenv.isDarwin && !(variant == "macport" || noGui)
, withPgtk ? false
, withSQLite3 ? lib.versionAtLeast version "29"
, withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd
, withToolkitScrollBars ? true
, withTreeSitter ? lib.versionAtLeast version "29"
, withWebP ? lib.versionAtLeast version "29"
, withX ? !(stdenv.isDarwin || noGui || withPgtk)
, withXinput2 ? withX && lib.versionAtLeast version "29"
, withXwidgets ? false
# Options
, siteStart ? ./site-start.el
, toolkit ? (
if withGTK2 then "gtk2"
else if withGTK3 then "gtk3"
else if withMotif then "motif"
else if withAthena then "athena"
else "lucid")
}:
assert (withGTK2 && !withNS && variant != "macport") -> withX;
assert (withGTK3 && !withNS && variant != "macport") -> withX || withPgtk;
assert noGui -> !(withX || withGTK2 || withGTK3 || withNS || variant == "macport");
assert withAcl -> stdenv.isLinux;
assert withAlsaLib -> stdenv.isLinux;
assert withGTK2 -> !(withGTK3 || withPgtk);
assert withGTK3 -> !withGTK2 || withPgtk;
assert withGconf -> withX;
assert withGpm -> stdenv.isLinux;
assert withNS -> stdenv.isDarwin && !(withX || variant == "macport");
assert withPgtk -> withGTK3 && !withX;
assert withXwidgets -> withGTK3;
let
libGccJitLibraryPaths = [
"${lib.getLib libgccjit}/lib/gcc"
"${lib.getLib stdenv.cc.libc}/lib"
] ++ lib.optionals (stdenv.cc?cc.libgcc) [
"${lib.getLib stdenv.cc.cc.libgcc}/lib"
];
inherit (if variant == "macport"
then llvmPackages_6.stdenv
else stdenv) mkDerivation;
in
mkDerivation (finalAttrs: (lib.optionalAttrs nativeComp {
env = {
NATIVE_FULL_AOT = "1";
LIBRARY_PATH = lib.concatStringsSep ":" libGccJitLibraryPaths;
};
} // {
pname = pname
+ (if noGui then "-nox"
else if withPgtk then "-pgtk"
else if withGTK3 then "-gtk3"
else if withGTK2 then "-gtk2"
else "");
inherit version;
inherit src;
patches = patches fetchpatch ++ lib.optionals nativeComp [
(substituteAll {
src = if lib.versionOlder finalAttrs.version "29"
then ./native-comp-driver-options-28.patch
else ./native-comp-driver-options.patch;
backendPath = (lib.concatStringsSep " "
(builtins.map (x: ''"-B${x}"'') ([
# Paths necessary so the JIT compiler finds its libraries:
"${lib.getLib libgccjit}/lib"
] ++ libGccJitLibraryPaths ++ [
# Executable paths necessary for compilation (ld, as):
"${lib.getBin stdenv.cc.cc}/bin"
"${lib.getBin stdenv.cc.bintools}/bin"
"${lib.getBin stdenv.cc.bintools.bintools}/bin"
])));
})
];
postPatch = lib.concatStringsSep "\n" [
(lib.optionalString srcRepo ''
rm -fr .git
'')
# Add the name of the wrapped gvfsd
# This used to be carried as a patch but it often got out of sync with
# upstream and was hard to maintain for emacs-overlay.
(lib.concatStrings (map (fn: ''
sed -i 's#(${fn} "gvfs-fuse-daemon")#(${fn} "gvfs-fuse-daemon") (${fn} ".gvfsd-fuse-wrapped")#' lisp/net/tramp-gvfs.el
'') [
"tramp-compat-process-running-p"
"tramp-process-running-p"
]))
# Reduce closure size by cleaning the environment of the emacs dumper
''
substituteInPlace src/Makefile.in \
--replace 'RUN_TEMACS = ./temacs' 'RUN_TEMACS = env -i ./temacs'
''
''
substituteInPlace lisp/international/mule-cmds.el \
--replace /usr/share/locale ${gettext}/share/locale
for makefile_in in $(find . -name Makefile.in -print); do
substituteInPlace $makefile_in --replace /bin/pwd pwd
done
''
""
];
nativeBuildInputs = [
makeWrapper
pkg-config
] ++ lib.optionals (variant == "macport") [
texinfo
] ++ lib.optionals srcRepo [
autoreconfHook
texinfo
] ++ lib.optional (withPgtk || withX && (withGTK3 || withXwidgets)) wrapGAppsHook;
buildInputs = [
gettext
gnutls
harfbuzz.dev
jansson
libxml2
ncurses
] ++ lib.optionals withGconf [
gconf
] ++ lib.optionals withAcl [
acl
] ++ lib.optionals withAlsaLib [
alsa-lib
] ++ lib.optionals withGpm [
gpm
] ++ lib.optionals stdenv.isLinux [
dbus
libselinux
] ++ lib.optionals (!stdenv.isDarwin && withGTK3) [
gsettings-desktop-schemas
] ++ lib.optionals (stdenv.isLinux && withX) [
libotf
m17n_lib
] ++ lib.optionals (withX && withGTK2) [
gtk2-x11
] ++ lib.optionals (withX && withGTK3) [
gtk3-x11
] ++ lib.optionals (withX && withMotif) [
motif
] ++ lib.optionals (withX && withXwidgets) [
glib-networking
webkitgtk
] ++ lib.optionals nativeComp [
libgccjit
] ++ lib.optionals withImageMagick [
imagemagick
] ++ lib.optionals withPgtk [
giflib
gtk3
libXpm
libjpeg
libpng
librsvg
libtiff
] ++ lib.optionals withSQLite3 [
sqlite
] ++ lib.optionals withSystemd [
systemd
] ++ lib.optionals withTreeSitter [
tree-sitter
] ++ lib.optionals withWebP [
libwebp
] ++ lib.optionals withX [
Xaw3d
cairo
giflib
libXaw
libXpm
libjpeg
libpng
librsvg
libtiff
] ++ lib.optionals stdenv.isDarwin [
sigtool
] ++ lib.optionals withNS [
librsvg
AppKit
GSS
ImageIO
] ++ lib.optionals (variant == "macport") [
AppKit
Carbon
Cocoa
IOKit
OSAKit
Quartz
QuartzCore
WebKit
# TODO are these optional?
GSS
ImageCaptureCore
ImageIO
];
hardeningDisable = [ "format" ];
configureFlags = [
"--disable-build-details" # for a (more) reproducible build
"--with-modules"
] ++ (if withNS then [
"--disable-ns-self-contained"
] else if withX then [
"--with-x-toolkit=${toolkit}"
"--with-xft"
"--with-cairo"
] else if withPgtk then [
"--with-pgtk"
] else [
"--with-gif=no"
"--with-jpeg=no"
"--with-png=no"
"--with-tiff=no"
"--with-x=no"
"--with-xpm=no"
])
++ lib.optionals (variant == "macport") [
"--enable-mac-app=$$out/Applications"
"--with-gnutls=yes"
"--with-mac"
"--with-xml2=yes"
]
++ (lib.optional stdenv.isDarwin (lib.withFeature withNS "ns"))
++ lib.optional (!withToolkitScrollBars) "--without-toolkit-scroll-bars"
++ lib.optional nativeComp "--with-native-compilation"
++ lib.optional withImageMagick "--with-imagemagick"
++ lib.optional withTreeSitter "--with-tree-sitter"
++ lib.optional withXinput2 "--with-xinput2"
++ lib.optional withXwidgets "--with-xwidgets"
;
enableParallelBuilding = true;
installTargets = [ "tags" "install" ];
postInstall = ''
mkdir -p $out/share/emacs/site-lisp
cp ${siteStart} $out/share/emacs/site-lisp/site-start.el
$out/bin/emacs --batch -f batch-byte-compile $out/share/emacs/site-lisp/site-start.el
siteVersionDir=`ls $out/share/emacs | grep -v site-lisp | head -n 1`
rm -r $out/share/emacs/$siteVersionDir/site-lisp
'' + lib.optionalString withCsrc ''
for srcdir in src lisp lwlib ; do
dstdir=$out/share/emacs/$siteVersionDir/$srcdir
mkdir -p $dstdir
find $srcdir -name "*.[chm]" -exec cp {} $dstdir \;
cp $srcdir/TAGS $dstdir
echo '((nil . ((tags-file-name . "TAGS"))))' > $dstdir/.dir-locals.el
done
'' + lib.optionalString withNS ''
mkdir -p $out/Applications
mv nextstep/Emacs.app $out/Applications
'' + lib.optionalString (nativeComp && (withNS || variant == "macport")) ''
ln -snf $out/lib/emacs/*/native-lisp $out/Applications/Emacs.app/Contents/native-lisp
'' + lib.optionalString nativeComp ''
echo "Generating native-compiled trampolines..."
# precompile trampolines in parallel, but avoid spawning one process per trampoline.
# 1000 is a rough lower bound on the number of trampolines compiled.
$out/bin/emacs --batch --eval "(mapatoms (lambda (s) \
(when (subr-primitive-p (symbol-function s)) (print s))))" \
| xargs -n $((1000/NIX_BUILD_CORES + 1)) -P $NIX_BUILD_CORES \
$out/bin/emacs --batch -l comp --eval "(while argv \
(comp-trampoline-compile (intern (pop argv))))"
mkdir -p $out/share/emacs/native-lisp
$out/bin/emacs --batch \
--eval "(add-to-list 'native-comp-eln-load-path \"$out/share/emacs/native-lisp\")" \
-f batch-native-compile $out/share/emacs/site-lisp/site-start.el
'';
postFixup = lib.optionalString (stdenv.isLinux && withX && toolkit == "lucid") ''
patchelf --add-rpath ${lib.makeLibraryPath [ libXcursor ]} $out/bin/emacs
patchelf --add-needed "libXcursor.so.1" "$out/bin/emacs"
'';
passthru = {
inherit nativeComp;
treeSitter = withTreeSitter;
pkgs = recurseIntoAttrs (emacsPackagesFor finalAttrs.finalPackage);
tests = { inherit (nixosTests) emacs-daemon; };
};
meta = {
homepage = if variant == "macport"
then "https://bitbucket.org/mituharu/emacs-mac/"
else "https://www.gnu.org/software/emacs/";
description = "The extensible, customizable GNU text editor"
+ lib.optionalString (variant == "macport") " - with macport patches";
longDescription = ''
GNU Emacs is an extensible, customizable text editor—and more. At its
core is an interpreter for Emacs Lisp, a dialect of the Lisp programming
language with extensions to support text editing.
The features of GNU Emacs include: content-sensitive editing modes,
including syntax coloring, for a wide variety of file types including
plain text, source code, and HTML; complete built-in documentation,
including a tutorial for new users; full Unicode support for nearly all
human languages and their scripts; highly customizable, using Emacs Lisp
code or a graphical interface; a large number of extensions that add other
functionality, including a project planner, mail and news reader, debugger
interface, calendar, and more. Many of these extensions are distributed
with GNU Emacs; others are available separately.
''
+ lib.optionalString (variant == "macport") ''
This release is built from Mitsuharu Yamamoto's patched, MacOS X-specific
source code.
'';
license = lib.licenses.gpl3Plus;
maintainers = with lib.maintainers; [
AndersonTorres
adisbladis
atemu
jwiegley
lovek323
matthewbauer
];
platforms = if variant == "macport"
then lib.platforms.darwin
else lib.platforms.all;
broken = !(stdenv.buildPlatform.canExecute stdenv.hostPlatform);
};
}))