From bb6708b8586e5ecc2ec2a70b19c342843651c5d2 Mon Sep 17 00:00:00 2001 From: Nicolas Dudebout Date: Mon, 26 Sep 2016 10:10:03 -0400 Subject: [PATCH 1/4] emacs: add an option to install the C source Install the source files, and the associated TAGS files. Use .dir-locals.el to select the TAGS file automatically. Turn the option on by default, to get a consistent behavior when using xref-find-definitions (M-.), whether looking for an elisp (e.g. defun) or a C (e.g. defalias) definition. --- pkgs/applications/editors/emacs/default.nix | 4 ++- .../editors/emacs/install-C-src.patch | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 pkgs/applications/editors/emacs/install-C-src.patch diff --git a/pkgs/applications/editors/emacs/default.nix b/pkgs/applications/editors/emacs/default.nix index 4a729ba3da3..e10be4ab22d 100644 --- a/pkgs/applications/editors/emacs/default.nix +++ b/pkgs/applications/editors/emacs/default.nix @@ -6,6 +6,7 @@ , withGTK2 ? true, gtk2 ? null , withGTK3 ? false, gtk3 ? null , withXwidgets ? false, webkitgtk24x ? null, wrapGAppsHook ? null, glib_networking ? null +, withCsrc ? true , srcRepo ? false, autoconf ? null, automake ? null, texinfo ? null }: @@ -31,7 +32,8 @@ stdenv.mkDerivation rec { sha256 = "0cwgyiyymnx4xdg99dm2drfxcyhy2jmyf0rkr9fwj9mwwf77kwhr"; }; - patches = lib.optional stdenv.isDarwin ./at-fdcwd.patch; + patches = lib.optional stdenv.isDarwin ./at-fdcwd.patch + ++ lib.optional withCsrc ./install-C-src.patch; nativeBuildInputs = [ pkgconfig ] ++ lib.optionals srcRepo [ autoconf automake texinfo ]; diff --git a/pkgs/applications/editors/emacs/install-C-src.patch b/pkgs/applications/editors/emacs/install-C-src.patch new file mode 100644 index 00000000000..eb980d3e078 --- /dev/null +++ b/pkgs/applications/editors/emacs/install-C-src.patch @@ -0,0 +1,33 @@ +diff --git a/Makefile.in b/Makefile.in +index 7aac403..c21a396 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -563,7 +563,7 @@ set_installuser= + ## work correctly, and therefore no idea when tar can be replaced. + ## See also these comments from 2004 about cp -r working fine: + ## http://lists.gnu.org/archive/html/autoconf-patches/2004-11/msg00005.html +-install-arch-indep: lisp install-info install-man ${INSTALL_ARCH_INDEP_EXTRA} ++install-arch-indep: lisp install-info install-man ${INSTALL_ARCH_INDEP_EXTRA} tags + -set ${COPYDESTS} ; \ + unset CDPATH; \ + $(set_installuser); \ +@@ -617,6 +617,19 @@ install-arch-indep: + done; \ + ${GZIP_PROG} -9n "../etc/publicsuffix.txt"; \ + } ++ for d in src lwlib ; do \ ++ srcdir="$(DESTDIR)${datadir}/emacs/${version}/$$d" ; \ ++ mkdir -p $$srcdir ; \ ++ find $$d -name "*.[chm]" -exec cp {} $$srcdir \; ; \ ++ done ++ for d in src lisp lwlib ; do \ ++ srcdir="$(DESTDIR)${datadir}/emacs/${version}/$$d" ; \ ++ cp $$d/TAGS $$srcdir ; \ ++ echo '((nil . ((tags-file-name . "TAGS"))))' > $$srcdir/.dir-locals.el ; \ ++ done ++ mkdir -p "$(DESTDIR)${datadir}/emacs/${version}/site-lisp" ++ echo "(setq find-function-C-source-directory \"$(DESTDIR)${datadir}/emacs/${version}/src\")" \ ++ > "$(DESTDIR)${datadir}/emacs/${version}/site-lisp/site-start.el" + -chmod -R a+r "$(DESTDIR)${datadir}/emacs/${version}" ${COPYDESTS} + + ## The above chmods are needed because "umask 022; tar ..." is not From 7e7d588ca936bca8c535f697d43b1c3b23b7e468 Mon Sep 17 00:00:00 2001 From: Nicolas Dudebout Date: Tue, 27 Sep 2016 15:57:52 -0400 Subject: [PATCH 2/4] emacs: install the C source from postInstall Reimplement the C source installation from the derivation instead of relying on a Makefile patch. --- pkgs/applications/editors/emacs/default.nix | 23 ++++++++++--- .../editors/emacs/install-C-src.patch | 33 ------------------- pkgs/applications/editors/emacs/site-start.el | 24 ++++++++++++-- 3 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 pkgs/applications/editors/emacs/install-C-src.patch diff --git a/pkgs/applications/editors/emacs/default.nix b/pkgs/applications/editors/emacs/default.nix index e10be4ab22d..08223ef82ef 100644 --- a/pkgs/applications/editors/emacs/default.nix +++ b/pkgs/applications/editors/emacs/default.nix @@ -25,15 +25,16 @@ let else "lucid"; in stdenv.mkDerivation rec { - name = "emacs-25.1"; + name = "emacs-${version}${versionModifier}"; + version = "25.1"; + versionModifier = ""; src = fetchurl { url = "mirror://gnu//emacs/${name}.tar.xz"; sha256 = "0cwgyiyymnx4xdg99dm2drfxcyhy2jmyf0rkr9fwj9mwwf77kwhr"; }; - patches = lib.optional stdenv.isDarwin ./at-fdcwd.patch - ++ lib.optional withCsrc ./install-C-src.patch; + patches = lib.optional stdenv.isDarwin ./at-fdcwd.patch; nativeBuildInputs = [ pkgconfig ] ++ lib.optionals srcRepo [ autoconf automake texinfo ]; @@ -73,9 +74,23 @@ stdenv.mkDerivation rec { done ''; + installTargets = "tags install"; + postInstall = '' - mkdir -p $out/share/emacs/site-lisp/ + mkdir -p $out/share/emacs/site-lisp cp ${./site-start.el} $out/share/emacs/site-lisp/site-start.el + $out/bin/emacs --batch -f batch-byte-compile $out/share/emacs/site-lisp/site-start.el + + rm -rf $out/var + rm -rf $out/share/emacs/${version}/site-lisp + '' + lib.optionalString withCsrc '' + for srcdir in src lisp lwlib ; do + dstdir=$out/share/emacs/${version}/$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 stdenv.isDarwin '' mkdir -p $out/Applications mv nextstep/Emacs.app $out/Applications diff --git a/pkgs/applications/editors/emacs/install-C-src.patch b/pkgs/applications/editors/emacs/install-C-src.patch deleted file mode 100644 index eb980d3e078..00000000000 --- a/pkgs/applications/editors/emacs/install-C-src.patch +++ /dev/null @@ -1,33 +0,0 @@ -diff --git a/Makefile.in b/Makefile.in -index 7aac403..c21a396 100644 ---- a/Makefile.in -+++ b/Makefile.in -@@ -563,7 +563,7 @@ set_installuser= - ## work correctly, and therefore no idea when tar can be replaced. - ## See also these comments from 2004 about cp -r working fine: - ## http://lists.gnu.org/archive/html/autoconf-patches/2004-11/msg00005.html --install-arch-indep: lisp install-info install-man ${INSTALL_ARCH_INDEP_EXTRA} -+install-arch-indep: lisp install-info install-man ${INSTALL_ARCH_INDEP_EXTRA} tags - -set ${COPYDESTS} ; \ - unset CDPATH; \ - $(set_installuser); \ -@@ -617,6 +617,19 @@ install-arch-indep: - done; \ - ${GZIP_PROG} -9n "../etc/publicsuffix.txt"; \ - } -+ for d in src lwlib ; do \ -+ srcdir="$(DESTDIR)${datadir}/emacs/${version}/$$d" ; \ -+ mkdir -p $$srcdir ; \ -+ find $$d -name "*.[chm]" -exec cp {} $$srcdir \; ; \ -+ done -+ for d in src lisp lwlib ; do \ -+ srcdir="$(DESTDIR)${datadir}/emacs/${version}/$$d" ; \ -+ cp $$d/TAGS $$srcdir ; \ -+ echo '((nil . ((tags-file-name . "TAGS"))))' > $$srcdir/.dir-locals.el ; \ -+ done -+ mkdir -p "$(DESTDIR)${datadir}/emacs/${version}/site-lisp" -+ echo "(setq find-function-C-source-directory \"$(DESTDIR)${datadir}/emacs/${version}/src\")" \ -+ > "$(DESTDIR)${datadir}/emacs/${version}/site-lisp/site-start.el" - -chmod -R a+r "$(DESTDIR)${datadir}/emacs/${version}" ${COPYDESTS} - - ## The above chmods are needed because "umask 022; tar ..." is not diff --git a/pkgs/applications/editors/emacs/site-start.el b/pkgs/applications/editors/emacs/site-start.el index 023d6412ed8..b41ca92db08 100644 --- a/pkgs/applications/editors/emacs/site-start.el +++ b/pkgs/applications/editors/emacs/site-start.el @@ -1,4 +1,4 @@ -;; NixOS specific load-path +;;; NixOS specific load-path (setq load-path (append (reverse (mapcar (lambda (x) (concat x "/share/emacs/site-lisp/")) (split-string (or (getenv "NIX_PROFILES") "")))) @@ -11,7 +11,25 @@ (split-string (or (getenv "NIX_PROFILES") "")))) woman-manpath))) -;; Make tramp work for remote NixOS machines -;;; NOTE: You might want to add +;;; Make tramp work for remote NixOS machines (eval-after-load 'tramp '(add-to-list 'tramp-remote-path "/run/current-system/sw/bin")) + +;;; C source directory +;;; +;;; Computes the location of the C source directory from the path of +;;; the current file: +;;; from: /nix/store/-emacs-/share/emacs/site-lisp/site-start.el +;;; to: /nix/store/-emacs-/share/emacs//src/ +(let ((emacs + (file-name-directory ;; .../emacs/ + (directory-file-name ;; .../emacs/site-lisp + (file-name-directory load-file-name)))) ;; .../emacs/site-lisp/ + (version + (file-name-as-directory + (concat + (number-to-string emacs-major-version) + "." + (number-to-string emacs-minor-version)))) + (src (file-name-as-directory "src"))) + (setq find-function-C-source-directory (concat emacs version src))) From 9c3852538c523263cad712fdd67d0904f967a131 Mon Sep 17 00:00:00 2001 From: Nicolas Dudebout Date: Tue, 27 Sep 2016 16:13:22 -0400 Subject: [PATCH 3/4] emacsWrapper: remove site-start.elc --- pkgs/build-support/emacs/wrapper.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix index 45931e6914a..b13def07bb8 100644 --- a/pkgs/build-support/emacs/wrapper.nix +++ b/pkgs/build-support/emacs/wrapper.nix @@ -85,13 +85,14 @@ stdenv.mkDerivation { done siteStart="$out/share/emacs/site-lisp/site-start.el" + siteStartByteCompiled="$siteStart"c # A dependency may have brought the original siteStart, delete it and # create our own # Begin the new site-start.el by loading the original, which sets some # NixOS-specific paths. Paths are searched in the reverse of the order # they are specified in, so user and system profile paths are searched last. - rm -f $siteStart + rm -f $siteStart $siteStartByteCompiled cat >"$siteStart" < Date: Fri, 30 Sep 2016 08:23:45 -0400 Subject: [PATCH 4/4] emacs-source-directory: remove --- pkgs/top-level/emacs-packages.nix | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/pkgs/top-level/emacs-packages.nix b/pkgs/top-level/emacs-packages.nix index 1e878e8b18c..430da89fc22 100644 --- a/pkgs/top-level/emacs-packages.nix +++ b/pkgs/top-level/emacs-packages.nix @@ -189,30 +189,6 @@ let }; }; - emacs-source-directory = stdenv.mkDerivation { - name = "emacs-source-directory-1.0.0"; - src = emacs.src; - - # We don't want accidentally start bulding emacs one more time - phases = "unpackPhase buildPhase"; - - buildPhase = '' - mkdir -p $out/share/emacs/site-lisp/elpa/emacs-source-directory - cp -a src $out/src - (cd $out/src && ${emacs}/bin/etags *.c *.h) - cat < $out/share/emacs/site-lisp/elpa/emacs-source-directory/emacs-source-directory-autoloads.el - (setq source-directory "$out") - (setq find-function-C-source-directory (expand-file-name "src" source-directory)) - EOF - cat < $out/share/emacs/site-lisp/elpa/emacs-source-directory/emacs-source-directory-pkg.el - (define-package "emacs-source-directory" "1.0.0" "Make emacs C source code available inside emacs. To use with emacsWithPackages in NixOS" '()) - EOF - ''; - meta = { - description = "Make emacs C source code available inside emacs. To use with emacsWithPackages in NixOS"; - }; - }; - evil-jumper = melpaBuild rec { pname = "evil-jumper"; version = "20151017";