From 470e40eb1f9826d06c712eaa42c36391f55d93b3 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sat, 15 Oct 2022 14:59:09 +0200 Subject: [PATCH 1/7] emacs: provide functional default for patches argument --- pkgs/applications/editors/emacs/28.nix | 1 - pkgs/applications/editors/emacs/generic.nix | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/applications/editors/emacs/28.nix b/pkgs/applications/editors/emacs/28.nix index 7ed37e0dfb541..b6abb4c4cdb57 100644 --- a/pkgs/applications/editors/emacs/28.nix +++ b/pkgs/applications/editors/emacs/28.nix @@ -1,5 +1,4 @@ import ./generic.nix (rec { version = "28.2"; sha256 = "sha256-4oSLcUDR0MOEt53QOiZSVU8kPJ67GwugmBxdX3F15Ag="; - patches = _: [ ]; }) diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index 5e455b6bcd9f5..0bcefd29aa328 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -4,7 +4,7 @@ , versionModifier ? "" , pname ? "emacs" , name ? "emacs-${version}${versionModifier}" - , patches ? [ ] + , patches ? _: [ ] }: { stdenv, lib, fetchurl, fetchpatch, ncurses, xlibsWrapper, libXaw, libXpm , Xaw3d, libXcursor, pkg-config, gettext, libXft, dbus, libpng, libjpeg, giflib From 76d7a14ed281f1c3be82bb47f2d4ef2513930a75 Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 17 Jan 2022 11:12:24 +0100 Subject: [PATCH 2/7] emacs: integrate macport into generic drv --- pkgs/applications/editors/emacs/generic.nix | 44 +++++-- pkgs/applications/editors/emacs/macport.nix | 127 +------------------- pkgs/top-level/all-packages.nix | 10 +- 3 files changed, 47 insertions(+), 134 deletions(-) diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index 0bcefd29aa328..9e3280d34ec85 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -5,18 +5,25 @@ , pname ? "emacs" , name ? "emacs-${version}${versionModifier}" , patches ? _: [ ] + , macportVersion ? null }: -{ stdenv, lib, fetchurl, fetchpatch, ncurses, xlibsWrapper, libXaw, libXpm +{ stdenv, llvmPackages_6, lib, fetchurl, fetchpatch, ncurses, xlibsWrapper, libXaw, libXpm , Xaw3d, libXcursor, pkg-config, gettext, libXft, dbus, libpng, libjpeg, giflib , libtiff, librsvg, libwebp, gconf, libxml2, imagemagick, gnutls, libselinux -, alsa-lib, cairo, acl, gpm, AppKit, GSS, ImageIO, m17n_lib, libotf +, alsa-lib, cairo, acl, gpm, m17n_lib, libotf , sigtool, jansson, harfbuzz, sqlite, nixosTests , recurseIntoAttrs, emacsPackagesFor , libgccjit, targetPlatform, makeWrapper # native-comp params -, fetchFromSavannah +, fetchFromSavannah, fetchFromBitbucket + + # macOS dependencies for NS and macPort +, AppKit, Carbon, Cocoa, IOKit, OSAKit, Quartz, QuartzCore, WebKit +, ImageCaptureCore, GSS, ImageIO # These may be optional + , systemd ? null , withX ? !stdenv.isDarwin && !withPgtk -, withNS ? stdenv.isDarwin +, withNS ? stdenv.isDarwin && !withMacport +, withMacport ? macportVersion != null , withGTK2 ? false, gtk2-x11 ? null , withGTK3 ? withPgtk, gtk3-x11 ? null, gsettings-desktop-schemas ? null , withXwidgets ? false, webkitgtk ? null, wrapGAppsHook ? null, glib-networking ? null @@ -44,15 +51,16 @@ assert (libXft != null) -> libpng != null; # probably a bug assert stdenv.isDarwin -> libXaw != null; # fails to link otherwise assert withNS -> !withX; assert withNS -> stdenv.isDarwin; -assert (withGTK2 && !withNS) -> withX; -assert (withGTK3 && !withNS) -> withX || withPgtk; +assert withMacport -> !withNS; +assert (withGTK2 && !withNS && !withMacport) -> withX; +assert (withGTK3 && !withNS && !withMacport) -> withX || withPgtk; assert withGTK2 -> !withGTK3 && gtk2-x11 != null && !withPgtk; assert withGTK3 -> !withGTK2 && ((gtk3-x11 != null) || withPgtk); assert withPgtk -> withGTK3 && !withX && gtk3 != null; assert withXwidgets -> withGTK3 && webkitgtk != null; -let emacs = stdenv.mkDerivation (lib.optionalAttrs nativeComp { +let emacs = (if withMacport then llvmPackages_6.stdenv else stdenv).mkDerivation (lib.optionalAttrs nativeComp { NATIVE_FULL_AOT = "1"; LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib"; } // { @@ -61,7 +69,12 @@ let emacs = stdenv.mkDerivation (lib.optionalAttrs nativeComp { patches = patches fetchpatch; - src = fetchFromSavannah { + src = if macportVersion != null then fetchFromBitbucket { + owner = "mituharu"; + repo = "emacs-mac"; + rev = macportVersion; + inherit sha256; + } else fetchFromSavannah { repo = "emacs"; rev = version; inherit sha256; @@ -143,6 +156,11 @@ let emacs = stdenv.mkDerivation (lib.optionalAttrs nativeComp { ++ lib.optional withWebP libwebp ++ lib.optionals (withX && withXwidgets) [ webkitgtk glib-networking ] ++ lib.optionals withNS [ AppKit GSS ImageIO ] + ++ lib.optionals withMacport [ + AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit + # TODO are these optional? + ImageCaptureCore GSS ImageIO + ] ++ lib.optionals stdenv.isDarwin [ sigtool ] ++ lib.optionals nativeComp [ libgccjit ]; @@ -160,6 +178,12 @@ let emacs = stdenv.mkDerivation (lib.optionalAttrs nativeComp { then [ "--with-x-toolkit=${toolkit}" "--with-xft" "--with-cairo" ] else [ "--with-x=no" "--with-xpm=no" "--with-jpeg=no" "--with-png=no" "--with-gif=no" "--with-tiff=no" ]) + ++ lib.optionals withMacport [ + "--with-mac" + "--enable-mac-app=$$out/Applications" + "--with-xml2=yes" + "--with-gnutls=yes" + ] ++ lib.optional withXwidgets "--with-xwidgets" ++ lib.optional nativeComp "--with-native-compilation" ++ lib.optional withImageMagick "--with-imagemagick" @@ -190,7 +214,7 @@ let emacs = stdenv.mkDerivation (lib.optionalAttrs nativeComp { '' + lib.optionalString withNS '' mkdir -p $out/Applications mv nextstep/Emacs.app $out/Applications - '' + lib.optionalString (nativeComp && withNS) '' + '' + lib.optionalString (nativeComp && (withNS || withMacport)) '' ln -snf $out/lib/emacs/*/native-lisp $out/Applications/Emacs.app/Contents/native-lisp '' + lib.optionalString nativeComp '' echo "Generating native-compiled trampolines..." @@ -222,7 +246,7 @@ let emacs = stdenv.mkDerivation (lib.optionalAttrs nativeComp { description = "The extensible, customizable GNU text editor"; homepage = "https://www.gnu.org/software/emacs/"; license = licenses.gpl3Plus; - maintainers = with maintainers; [ lovek323 jwiegley adisbladis ]; + maintainers = with maintainers; [ lovek323 jwiegley adisbladis matthewbauer ]; platforms = platforms.all; longDescription = '' diff --git a/pkgs/applications/editors/emacs/macport.nix b/pkgs/applications/editors/emacs/macport.nix index 8d210f822bf30..9a30b2b5b408b 100644 --- a/pkgs/applications/editors/emacs/macport.nix +++ b/pkgs/applications/editors/emacs/macport.nix @@ -1,123 +1,6 @@ -{ lib, stdenv, fetchurl, ncurses, pkg-config, texinfo, libxml2, gnutls, gettext, autoconf, automake, jansson -, AppKit, Carbon, Cocoa, IOKit, OSAKit, Quartz, QuartzCore, WebKit -, ImageCaptureCore, GSS, ImageIO # These may be optional -}: - -stdenv.mkDerivation rec { - pname = "emacs"; - version = "28.1"; - - emacsName = "emacs-${version}"; - macportVersion = "9.0"; - name = "emacs-mac-${version}-${macportVersion}"; - - src = fetchurl { - url = "mirror://gnu/emacs/${emacsName}.tar.xz"; - sha256 = "1qbmmmhnjhn4lvzsnyk7l5ganbi6wzbm38jc1a7hhyh3k78b7c98"; - }; - - macportSrc = fetchurl { - url = "ftp://ftp.math.s.chiba-u.ac.jp/emacs/${emacsName}-mac-${macportVersion}.tar.gz"; - sha256 = "10gyynz8wblz6r6dkk12m98kjbsmdwcbrhxpmsjylmdqmjxhlj4m"; - name = "${emacsName}-mac-${macportVersion}.tar.xz"; # It's actually compressed with xz, not gz - }; - - hiresSrc = fetchurl { - url = "ftp://ftp.math.s.chiba-u.ac.jp/emacs/emacs-hires-icons-3.0.tar.gz"; - sha256 = "0f2wzdw2a3ac581322b2y79rlj3c9f33ddrq9allj97r1si6v5xk"; - }; - - enableParallelBuilding = true; - - nativeBuildInputs = [ pkg-config autoconf automake ]; - - buildInputs = [ ncurses libxml2 gnutls texinfo gettext jansson - AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit - ImageCaptureCore GSS ImageIO # may be optional - ]; - - postUnpack = '' - mv $sourceRoot $name - tar xf $macportSrc -C $name --strip-components=1 - mv $name $sourceRoot - - # extract retina image resources - tar xfv $hiresSrc --strip 1 -C $sourceRoot - ''; - - postPatch = '' - patch -p1 < patch-mac - substituteInPlace lisp/international/mule-cmds.el \ - --replace /usr/share/locale ${gettext}/share/locale - - # use newer emacs icon - cp nextstep/Cocoa/Emacs.base/Contents/Resources/Emacs.icns mac/Emacs.app/Contents/Resources/Emacs.icns - - # Fix sandbox impurities. - substituteInPlace Makefile.in --replace '/bin/pwd' 'pwd' - substituteInPlace lib-src/Makefile.in --replace '/bin/pwd' 'pwd' - - # Reduce closure size by cleaning the environment of the emacs dumper - substituteInPlace src/Makefile.in \ - --replace 'RUN_TEMACS = ./temacs' 'RUN_TEMACS = env -i ./temacs' - ''; - - configureFlags = [ - "LDFLAGS=-L${ncurses.out}/lib" - "--with-xml2=yes" - "--with-gnutls=yes" - "--with-mac" - "--with-modules" - "--enable-mac-app=$$out/Applications" - ]; - - CFLAGS = "-O3"; - LDFLAGS = "-O3 -L${ncurses.out}/lib"; - - postInstall = '' - mkdir -p $out/share/emacs/site-lisp/ - cp ${./site-start.el} $out/share/emacs/site-lisp/site-start.el - ''; - - # fails with: - - # Ran 3870 tests, 3759 results as expected, 6 unexpected, 105 skipped - # 5 files contained unexpected results: - # lisp/url/url-handlers-test.log - # lisp/simple-tests.log - # lisp/files-x-tests.log - # lisp/cedet/srecode-utest-template.log - # lisp/net/tramp-tests.log - doCheck = false; - - meta = with lib; { - description = "The extensible, customizable text editor"; - homepage = "https://www.gnu.org/software/emacs/"; - license = licenses.gpl3Plus; - maintainers = with maintainers; [ jwiegley matthewbauer ]; - platforms = platforms.darwin; - - 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. - - This is the "Mac port" addition to GNU Emacs. This provides a native - GUI support for Mac OS X 10.6 - 10.12. Note that Emacs 23 and later - already contain the official GUI support via the NS (Cocoa) port for - Mac OS X 10.4 and later. So if it is good enough for you, then you - don't need to try this. - ''; - }; +import ./generic.nix rec { + pname = "emacs-mac"; + version = "28.2"; + macportVersion = "emacs-${version}-mac-9.1"; + sha256 = "sha256-Ne2jQ2nVLNiQmnkkOXVc5AkLVkTpm8pFC7VNY2gQjPE="; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index df2dfd32e44ee..a4d0531dfa610 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -27764,7 +27764,9 @@ with pkgs; alsa-lib = null; acl = null; gpm = null; - inherit (darwin.apple_sdk.frameworks) AppKit GSS ImageIO; + inherit (darwin.apple_sdk.frameworks) + AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit + ImageCaptureCore GSS ImageIO; inherit (darwin) sigtool; }; @@ -27780,10 +27782,14 @@ with pkgs; }); emacsMacport = callPackage ../applications/editors/emacs/macport.nix { + withMacport = true; + + gconf = null; + inherit (darwin.apple_sdk.frameworks) AppKit Carbon Cocoa IOKit OSAKit Quartz QuartzCore WebKit ImageCaptureCore GSS ImageIO; - stdenv = if stdenv.cc.isClang then llvmPackages_6.stdenv else stdenv; + inherit (darwin) sigtool; }; emacsPackagesFor = emacs: import ./emacs-packages.nix { From 0ae5a9688b02f8b68bb6ce52d844f19e97bee662 Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 17 Jan 2022 12:26:37 +0100 Subject: [PATCH 3/7] emacs: move Linux-only buildInputs where they belong --- pkgs/applications/editors/emacs/generic.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index 9e3280d34ec85..1b3eed84b84e3 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -139,8 +139,8 @@ let emacs = (if withMacport then llvmPackages_6.stdenv else stdenv).mkDerivation ++ lib.optional (withX && (withGTK3 || withXwidgets)) wrapGAppsHook; buildInputs = - [ ncurses gconf libxml2 gnutls alsa-lib acl gpm gettext jansson harfbuzz.dev ] - ++ lib.optionals stdenv.isLinux [ dbus libselinux systemd ] + [ ncurses gconf libxml2 gnutls gettext jansson harfbuzz.dev ] + ++ lib.optionals stdenv.isLinux [ dbus libselinux systemd alsa-lib acl gpm ] ++ lib.optionals withX [ xlibsWrapper libXaw Xaw3d libXpm libpng libjpeg giflib libtiff libXft gconf cairo ] From 45d9595b419a536b218337396517d57db17566aa Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 17 Jan 2022 19:28:41 +0100 Subject: [PATCH 4/7] emacs: consider macport in meta --- pkgs/applications/editors/emacs/generic.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index 1b3eed84b84e3..febf3a48eec10 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -243,11 +243,11 @@ let emacs = (if withMacport then llvmPackages_6.stdenv else stdenv).mkDerivation }; meta = with lib; { - description = "The extensible, customizable GNU text editor"; - homepage = "https://www.gnu.org/software/emacs/"; + 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/"; license = licenses.gpl3Plus; maintainers = with maintainers; [ lovek323 jwiegley adisbladis matthewbauer ]; - platforms = platforms.all; + platforms = if withMacport then platforms.darwin else platforms.all; longDescription = '' GNU Emacs is an extensible, customizable text editor—and more. At its From 338701e3dea21ebab307ad11bca5dd4e8598e448 Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 17 Jan 2022 19:30:11 +0100 Subject: [PATCH 5/7] emacs: add myself as maintainer I added macport support to the generic drv and will maintain that part --- pkgs/applications/editors/emacs/generic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index febf3a48eec10..94c92539e4cae 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -246,7 +246,7 @@ let emacs = (if withMacport then llvmPackages_6.stdenv else stdenv).mkDerivation 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/"; license = licenses.gpl3Plus; - maintainers = with maintainers; [ lovek323 jwiegley adisbladis matthewbauer ]; + maintainers = with maintainers; [ lovek323 jwiegley adisbladis matthewbauer atemu ]; platforms = if withMacport then platforms.darwin else platforms.all; longDescription = '' From d34513014f7b695e39d42ae8ed514b480710573b Mon Sep 17 00:00:00 2001 From: Atemu Date: Mon, 17 Jan 2022 22:33:49 +0100 Subject: [PATCH 6/7] emacs: always put texinfo in nativeBuildinputs for macport builds Non-source macport builds require it --- pkgs/applications/editors/emacs/generic.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index 94c92539e4cae..f0e97a07194fa 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -135,7 +135,8 @@ let emacs = (if withMacport then llvmPackages_6.stdenv else stdenv).mkDerivation ]; nativeBuildInputs = [ pkg-config makeWrapper ] - ++ lib.optionals srcRepo [ autoreconfHook texinfo ] + ++ lib.optionals (srcRepo || withMacport) [ texinfo ] + ++ lib.optionals srcRepo [ autoreconfHook ] ++ lib.optional (withX && (withGTK3 || withXwidgets)) wrapGAppsHook; buildInputs = From 5dd7a6e33dbb737e475d6547a9e71acee43b1810 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sat, 15 Oct 2022 15:08:46 +0200 Subject: [PATCH 7/7] emacs: don't call macport emacs -nox --- pkgs/applications/editors/emacs/generic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index f0e97a07194fa..91110c48a74b2 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -64,7 +64,7 @@ let emacs = (if withMacport then llvmPackages_6.stdenv else stdenv).mkDerivation NATIVE_FULL_AOT = "1"; LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib"; } // { - pname = pname + lib.optionalString ( !withX && !withNS && !withGTK2 && !withGTK3 ) "-nox"; + pname = pname + lib.optionalString ( !withX && !withNS && !withMacport && !withGTK2 && !withGTK3 ) "-nox"; inherit version; patches = patches fetchpatch;