2020-09-25 04:45:31 +00:00
|
|
|
{
|
|
|
|
version
|
|
|
|
, sha256
|
|
|
|
, versionModifier ? ""
|
|
|
|
, pname ? "emacs"
|
|
|
|
, name ? "emacs-${version}${versionModifier}"
|
2022-10-21 18:38:19 +00:00
|
|
|
, patches ? _: [ ]
|
|
|
|
, macportVersion ? null
|
2020-09-25 04:45:31 +00:00
|
|
|
}:
|
2022-12-02 08:20:57 +00:00
|
|
|
{ stdenv, llvmPackages_6, lib, fetchurl, fetchpatch, substituteAll, ncurses, libXaw, libXpm
|
2021-05-20 23:08:51 +00:00
|
|
|
, Xaw3d, libXcursor, pkg-config, gettext, libXft, dbus, libpng, libjpeg, giflib
|
2022-04-27 09:35:20 +00:00
|
|
|
, libtiff, librsvg, libwebp, gconf, libxml2, imagemagick, gnutls, libselinux
|
2022-10-21 18:38:19 +00:00
|
|
|
, alsa-lib, cairo, acl, gpm, m17n_lib, libotf
|
2022-01-25 03:21:06 +00:00
|
|
|
, sigtool, jansson, harfbuzz, sqlite, nixosTests
|
2022-09-09 14:08:57 +00:00
|
|
|
, recurseIntoAttrs, emacsPackagesFor
|
2023-01-11 07:51:40 +00:00
|
|
|
, libgccjit, makeWrapper # native-comp params
|
2022-10-21 18:38:19 +00:00
|
|
|
, fetchFromSavannah, fetchFromBitbucket
|
|
|
|
|
|
|
|
# macOS dependencies for NS and macPort
|
|
|
|
, AppKit, Carbon, Cocoa, IOKit, OSAKit, Quartz, QuartzCore, WebKit
|
|
|
|
, ImageCaptureCore, GSS, ImageIO # These may be optional
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
, withX ? !stdenv.isDarwin && !withPgtk
|
2022-10-21 18:38:19 +00:00
|
|
|
, withNS ? stdenv.isDarwin && !withMacport
|
|
|
|
, withMacport ? macportVersion != null
|
2020-04-24 23:36:52 +00:00
|
|
|
, withGTK2 ? false, gtk2-x11 ? null
|
2022-09-09 14:08:57 +00:00
|
|
|
, withGTK3 ? withPgtk, gtk3-x11 ? null, gsettings-desktop-schemas ? null
|
2020-04-24 23:36:52 +00:00
|
|
|
, withXwidgets ? false, webkitgtk ? null, wrapGAppsHook ? null, glib-networking ? null
|
2021-02-13 14:23:35 +00:00
|
|
|
, withMotif ? false, motif ? null
|
2021-12-19 01:06:50 +00:00
|
|
|
, withSQLite3 ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
, withCsrc ? true
|
2022-04-27 09:35:20 +00:00
|
|
|
, withWebP ? false
|
|
|
|
, srcRepo ? true, autoreconfHook ? null, texinfo ? null
|
2020-04-24 23:36:52 +00:00
|
|
|
, siteStart ? ./site-start.el
|
2022-08-21 13:32:41 +00:00
|
|
|
, nativeComp ? true
|
2022-03-05 16:20:37 +00:00
|
|
|
, withAthena ? false
|
|
|
|
, withToolkitScrollBars ? true
|
2022-09-09 14:08:57 +00:00
|
|
|
, withPgtk ? false, gtk3 ? null
|
|
|
|
, withXinput2 ? withX && lib.versionAtLeast version "29"
|
2020-11-21 19:51:51 +00:00
|
|
|
, withImageMagick ? lib.versionOlder version "27" && (withX || withNS)
|
2020-05-29 06:06:01 +00:00
|
|
|
, toolkit ? (
|
|
|
|
if withGTK2 then "gtk2"
|
|
|
|
else if withGTK3 then "gtk3"
|
2021-02-13 14:23:35 +00:00
|
|
|
else if withMotif then "motif"
|
2022-03-05 16:20:37 +00:00
|
|
|
else if withAthena then "athena"
|
2020-05-29 06:06:01 +00:00
|
|
|
else "lucid")
|
2022-11-21 17:40:18 +00:00
|
|
|
, withSystemd ? stdenv.isLinux, systemd
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert (libXft != null) -> libpng != null; # probably a bug
|
|
|
|
assert stdenv.isDarwin -> libXaw != null; # fails to link otherwise
|
|
|
|
assert withNS -> !withX;
|
|
|
|
assert withNS -> stdenv.isDarwin;
|
2022-10-21 18:38:19 +00:00
|
|
|
assert withMacport -> !withNS;
|
|
|
|
assert (withGTK2 && !withNS && !withMacport) -> withX;
|
|
|
|
assert (withGTK3 && !withNS && !withMacport) -> withX || withPgtk;
|
2022-09-09 14:08:57 +00:00
|
|
|
assert withGTK2 -> !withGTK3 && gtk2-x11 != null && !withPgtk;
|
|
|
|
assert withGTK3 -> !withGTK2 && ((gtk3-x11 != null) || withPgtk);
|
|
|
|
assert withPgtk -> withGTK3 && !withX && gtk3 != null;
|
2020-04-24 23:36:52 +00:00
|
|
|
assert withXwidgets -> withGTK3 && webkitgtk != null;
|
|
|
|
|
2020-05-29 06:06:01 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
let emacs = (if withMacport then llvmPackages_6.stdenv else stdenv).mkDerivation (lib.optionalAttrs nativeComp {
|
2020-12-25 13:55:36 +00:00
|
|
|
NATIVE_FULL_AOT = "1";
|
|
|
|
LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";
|
|
|
|
} // {
|
2022-10-21 18:38:19 +00:00
|
|
|
pname = pname + lib.optionalString ( !withX && !withNS && !withMacport && !withGTK2 && !withGTK3 ) "-nox";
|
2022-03-05 16:20:37 +00:00
|
|
|
inherit version;
|
2021-06-28 23:13:55 +00:00
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
patches = patches fetchpatch ++ lib.optionals nativeComp [
|
|
|
|
(substituteAll {
|
|
|
|
src = if lib.versionOlder 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"
|
|
|
|
"${lib.getLib libgccjit}/lib/gcc"
|
|
|
|
"${lib.getLib stdenv.cc.libc}/lib"
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
]));
|
|
|
|
})
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
src = if macportVersion != null then fetchFromBitbucket {
|
|
|
|
owner = "mituharu";
|
|
|
|
repo = "emacs-mac";
|
|
|
|
rev = macportVersion;
|
|
|
|
inherit sha256;
|
|
|
|
} else fetchFromSavannah {
|
2022-04-27 09:35:20 +00:00
|
|
|
repo = "emacs";
|
|
|
|
rev = version;
|
2020-09-25 04:45:31 +00:00
|
|
|
inherit sha256;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
postPatch = lib.concatStringsSep "\n" [
|
|
|
|
(lib.optionalString srcRepo ''
|
|
|
|
rm -fr .git
|
|
|
|
'')
|
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
# 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"
|
|
|
|
]))
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
# Reduce closure size by cleaning the environment of the emacs dumper
|
|
|
|
''
|
|
|
|
substituteInPlace src/Makefile.in \
|
|
|
|
--replace 'RUN_TEMACS = ./temacs' 'RUN_TEMACS = env -i ./temacs'
|
|
|
|
''
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
''
|
|
|
|
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
|
|
|
|
''
|
|
|
|
|
|
|
|
""
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
nativeBuildInputs = [ pkg-config makeWrapper ]
|
2022-10-21 18:38:19 +00:00
|
|
|
++ lib.optionals (srcRepo || withMacport) [ texinfo ]
|
|
|
|
++ lib.optionals srcRepo [ autoreconfHook ]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ lib.optional (withX && (withGTK3 || withXwidgets)) wrapGAppsHook;
|
|
|
|
|
|
|
|
buildInputs =
|
2022-10-21 18:38:19 +00:00
|
|
|
[ ncurses gconf libxml2 gnutls gettext jansson harfbuzz.dev ]
|
2022-11-21 17:40:18 +00:00
|
|
|
++ lib.optionals stdenv.isLinux [ dbus libselinux alsa-lib acl gpm ]
|
|
|
|
++ lib.optionals withSystemd [ systemd ]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ lib.optionals withX
|
2022-12-02 08:20:57 +00:00
|
|
|
[ libXaw Xaw3d gconf cairo ]
|
2022-11-27 09:42:12 +00:00
|
|
|
++ lib.optionals (withX || withPgtk)
|
|
|
|
[ libXpm libpng libjpeg giflib libtiff ]
|
|
|
|
++ lib.optionals (withX || withNS || withPgtk ) [ librsvg ]
|
2020-11-21 19:51:51 +00:00
|
|
|
++ lib.optionals withImageMagick [ imagemagick ]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ lib.optionals (stdenv.isLinux && withX) [ m17n_lib libotf ]
|
|
|
|
++ lib.optional (withX && withGTK2) gtk2-x11
|
2022-09-09 14:08:57 +00:00
|
|
|
++ lib.optional (withX && withGTK3) gtk3-x11
|
2022-09-22 12:36:57 +00:00
|
|
|
++ lib.optional (!stdenv.isDarwin && withGTK3) gsettings-desktop-schemas
|
2022-09-09 14:08:57 +00:00
|
|
|
++ lib.optional withPgtk gtk3
|
2021-02-13 14:23:35 +00:00
|
|
|
++ lib.optional (withX && withMotif) motif
|
2021-12-19 01:06:50 +00:00
|
|
|
++ lib.optional withSQLite3 sqlite
|
2022-04-27 09:35:20 +00:00
|
|
|
++ lib.optional withWebP libwebp
|
2020-04-24 23:36:52 +00:00
|
|
|
++ lib.optionals (withX && withXwidgets) [ webkitgtk glib-networking ]
|
2020-08-20 17:08:02 +00:00
|
|
|
++ lib.optionals withNS [ AppKit GSS ImageIO ]
|
2022-10-21 18:38:19 +00:00
|
|
|
++ lib.optionals withMacport [
|
|
|
|
AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit
|
|
|
|
# TODO are these optional?
|
|
|
|
ImageCaptureCore GSS ImageIO
|
|
|
|
]
|
2021-06-28 23:13:55 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ sigtool ]
|
|
|
|
++ lib.optionals nativeComp [ libgccjit ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
hardeningDisable = [ "format" ];
|
|
|
|
|
|
|
|
configureFlags = [
|
|
|
|
"--disable-build-details" # for a (more) reproducible build
|
|
|
|
"--with-modules"
|
|
|
|
] ++
|
|
|
|
(lib.optional stdenv.isDarwin
|
|
|
|
(lib.withFeature withNS "ns")) ++
|
|
|
|
(if withNS
|
|
|
|
then [ "--disable-ns-self-contained" ]
|
|
|
|
else if withX
|
2020-08-20 17:08:02 +00:00
|
|
|
then [ "--with-x-toolkit=${toolkit}" "--with-xft" "--with-cairo" ]
|
2022-11-27 09:42:12 +00:00
|
|
|
else if withPgtk
|
|
|
|
then [ "--with-pgtk" ]
|
|
|
|
else [ "--with-x=no" "--with-xpm=no" "--with-jpeg=no" "--with-png=no"
|
|
|
|
"--with-gif=no" "--with-tiff=no" ])
|
2022-10-21 18:38:19 +00:00
|
|
|
++ lib.optionals withMacport [
|
|
|
|
"--with-mac"
|
|
|
|
"--enable-mac-app=$$out/Applications"
|
|
|
|
"--with-xml2=yes"
|
|
|
|
"--with-gnutls=yes"
|
|
|
|
]
|
2020-08-20 17:08:02 +00:00
|
|
|
++ lib.optional withXwidgets "--with-xwidgets"
|
2021-03-09 03:18:52 +00:00
|
|
|
++ lib.optional nativeComp "--with-native-compilation"
|
2020-11-21 19:51:51 +00:00
|
|
|
++ lib.optional withImageMagick "--with-imagemagick"
|
2021-12-30 13:39:12 +00:00
|
|
|
++ lib.optional withXinput2 "--with-xinput2"
|
2022-03-05 16:20:37 +00:00
|
|
|
++ lib.optional (!withToolkitScrollBars) "--without-toolkit-scroll-bars"
|
2021-06-28 23:13:55 +00:00
|
|
|
;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
installTargets = [ "tags" "install" ];
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
mkdir -p $out/share/emacs/site-lisp
|
|
|
|
cp ${siteStart} $out/share/emacs/site-lisp/site-start.el
|
2020-08-20 17:08:02 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
$out/bin/emacs --batch -f batch-byte-compile $out/share/emacs/site-lisp/site-start.el
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
siteVersionDir=`ls $out/share/emacs | grep -v site-lisp | head -n 1`
|
|
|
|
|
2020-12-25 13:55:36 +00:00
|
|
|
rm -r $out/share/emacs/$siteVersionDir/site-lisp
|
2020-04-24 23:36:52 +00:00
|
|
|
'' + lib.optionalString withCsrc ''
|
|
|
|
for srcdir in src lisp lwlib ; do
|
2020-11-24 20:58:05 +00:00
|
|
|
dstdir=$out/share/emacs/$siteVersionDir/$srcdir
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
2022-10-21 18:38:19 +00:00
|
|
|
'' + lib.optionalString (nativeComp && (withNS || withMacport)) ''
|
2020-12-07 07:45:13 +00:00
|
|
|
ln -snf $out/lib/emacs/*/native-lisp $out/Applications/Emacs.app/Contents/native-lisp
|
2020-12-25 13:55:36 +00:00
|
|
|
'' + lib.optionalString nativeComp ''
|
2021-02-22 21:28:39 +00:00
|
|
|
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))))"
|
2020-12-25 13:55:36 +00:00
|
|
|
mkdir -p $out/share/emacs/native-lisp
|
|
|
|
$out/bin/emacs --batch \
|
2021-05-20 23:08:51 +00:00
|
|
|
--eval "(add-to-list 'native-comp-eln-load-path \"$out/share/emacs/native-lisp\")" \
|
2020-12-25 13:55:36 +00:00
|
|
|
-f batch-native-compile $out/share/emacs/site-lisp/site-start.el
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
postFixup = lib.optionalString (stdenv.isLinux && withX && toolkit == "lucid") ''
|
|
|
|
patchelf --add-rpath ${lib.makeLibraryPath [ libXcursor ]} $out/bin/emacs
|
2020-04-24 23:36:52 +00:00
|
|
|
patchelf --add-needed "libXcursor.so.1" "$out/bin/emacs"
|
2022-09-09 14:08:57 +00:00
|
|
|
'';
|
2020-08-20 17:08:02 +00:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit nativeComp;
|
2022-09-09 14:08:57 +00:00
|
|
|
pkgs = recurseIntoAttrs (emacsPackagesFor emacs);
|
2022-01-25 03:21:06 +00:00
|
|
|
tests = { inherit (nixosTests) emacs-daemon; };
|
2020-08-20 17:08:02 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2022-10-21 18:38:19 +00:00
|
|
|
description = "The extensible, customizable GNU text editor" + optionalString withMacport " with Mitsuharu Yamamoto's macport patches";
|
|
|
|
homepage = if withMacport then "https://bitbucket.org/mituharu/emacs-mac/" else "https://www.gnu.org/software/emacs/";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.gpl3Plus;
|
2022-10-21 18:38:19 +00:00
|
|
|
maintainers = with maintainers; [ lovek323 jwiegley adisbladis matthewbauer atemu ];
|
|
|
|
platforms = if withMacport then platforms.darwin else platforms.all;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2021-01-15 22:18:51 +00:00
|
|
|
});
|
|
|
|
in emacs
|