From 4092c0d8507cea3068cf7ad2c58e8d1d2a3cb676 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Fri, 20 Sep 2024 08:55:10 +0800 Subject: [PATCH] emacs: make trivialBuild know its elisp dependencies in another way Previously, trivialBuild did not know how to find its elisp dependencies. This was[1] fixed[2] by basically rewriting part of package-activate-all in bash. I think it is better to call package-activate-all (or package-initialize if Emacs is old) directly. It reduces maintenance burden a bit. It also improves consistency since elpaBuild and melpaBuild already do so. This change provides almost the same functionality as before. It only breaks elisp packages with non-standard[^3] elisp dependencies. However, I think those non-standard ones should be fixed instead. As an example, mu4e used to be a non-standard one and was fixed[4]. This change does not cause more build failures in emacsPackages. [1]: https://github.com/NixOS/nixpkgs/pull/82604 [2]: https://github.com/NixOS/nixpkgs/commit/bf486f784ddd969c03243dba4c93d0e8e861173e [^3]: Non-standard elisp packages do not meet requirements of package.el, the builtin package manager of Emacs. Usually, they are installed to $out/share/emacs/site-lisp/$pname-$version and/or miss a $pname-pkg.el file. [4]: https://github.com/NixOS/nixpkgs/pull/253438 --- .../editors/emacs/build-support/emacs-funcs.sh | 11 ----------- .../editors/emacs/build-support/generic.nix | 4 ++++ .../editors/emacs/build-support/trivial.nix | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/pkgs/applications/editors/emacs/build-support/emacs-funcs.sh b/pkgs/applications/editors/emacs/build-support/emacs-funcs.sh index e1e6a3b62208..b6b2a3bd374d 100644 --- a/pkgs/applications/editors/emacs/build-support/emacs-funcs.sh +++ b/pkgs/applications/editors/emacs/build-support/emacs-funcs.sh @@ -20,15 +20,4 @@ addEmacsVars () { if [ -n "${addEmacsNativeLoadPath:-}" ]; then addToEmacsNativeLoadPath "$1/share/emacs/native-lisp" fi - - # Add sub paths to the Emacs load path if it is a directory - # containing .el files. This is necessary to build some packages, - # e.g., using trivialBuild. - for lispDir in \ - "$1/share/emacs/site-lisp/"* \ - "$1/share/emacs/site-lisp/elpa/"*; do - if [[ -d $lispDir && "$(echo "$lispDir"/*.el)" ]] ; then - addToEmacsLoadPath "$lispDir" - fi - done } diff --git a/pkgs/applications/editors/emacs/build-support/generic.nix b/pkgs/applications/editors/emacs/build-support/generic.nix index 9f1b2308cc43..b032b587b798 100644 --- a/pkgs/applications/editors/emacs/build-support/generic.nix +++ b/pkgs/applications/editors/emacs/build-support/generic.nix @@ -86,10 +86,14 @@ libBuildHelper.extendMkDerivation' stdenv.mkDerivation (finalAttrs: source ${./emacs-funcs.sh} addEmacsVars "$out" + # package-activate-all is used to activate packages. In other builder + # helpers, package-initialize is used for this purpose because + # package-activate-all is not available before Emacs 27. find $out/share/emacs -type f -name '*.el' -not -name ".dir-locals.el" -print0 \ | xargs --verbose -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \ "emacs \ --batch \ + -f package-activate-all \ --eval '(setq native-comp-eln-load-path (cdr native-comp-eln-load-path))' \ --eval '(setq large-file-warning-threshold nil)' \ --eval '(setq byte-compile-error-on-warn ${if finalAttrs.turnCompilationWarningToError then "t" else "nil"})' \ diff --git a/pkgs/applications/editors/emacs/build-support/trivial.nix b/pkgs/applications/editors/emacs/build-support/trivial.nix index 8c515363f427..2e4da1ca8ea0 100644 --- a/pkgs/applications/editors/emacs/build-support/trivial.nix +++ b/pkgs/applications/editors/emacs/build-support/trivial.nix @@ -19,7 +19,7 @@ args: foundMakefile=1 fi - emacs -L . --batch -f batch-byte-compile *.el + emacs -l package -f package-initialize -L . --batch -f batch-byte-compile *.el runHook postBuild '';