1 # generic builder for Emacs packages
3 { lib, stdenv, emacs, texinfo, writeText, ... }:
6 inherit (lib) optionalAttrs;
8 setupHook = writeText "setup-hook.sh" ''
9 source ${./emacs-funcs.sh}
11 if [[ ! -v emacsHookDone ]]; then
14 # If this is for a wrapper derivation, emacs and the dependencies are all
15 # run-time dependencies. If this is for precompiling packages into bytecode,
16 # emacs is a compile-time dependency of the package.
17 addEnvHooks "$hostOffset" addEmacsVars
18 addEnvHooks "$targetOffset" addEmacsVars
22 libBuildHelper = import ./lib-build-helper.nix;
26 libBuildHelper.extendMkDerivation' stdenv.mkDerivation (finalAttrs:
29 , nativeBuildInputs ? []
30 , packageRequires ? []
31 , propagatedBuildInputs ? []
32 , propagatedUserEnvPkgs ? []
35 , turnCompilationWarningToError ? false
36 , ignoreCompilationError ? false
41 name = args.name or "emacs-${finalAttrs.pname}-${finalAttrs.version}";
43 unpackCmd = args.unpackCmd or ''
46 # keep original source filename without the hash
47 local filename=$(basename "$curSrc")
48 filename="''${filename:33}"
54 _defaultUnpack "$curSrc"
59 inherit packageRequires;
60 buildInputs = finalAttrs.packageRequires ++ buildInputs;
61 nativeBuildInputs = [ emacs texinfo ] ++ nativeBuildInputs;
62 propagatedBuildInputs = finalAttrs.packageRequires ++ propagatedBuildInputs;
63 propagatedUserEnvPkgs = finalAttrs.packageRequires ++ propagatedUserEnvPkgs;
65 setupHook = args.setupHook or setupHook;
67 inherit turnCompilationWarningToError ignoreCompilationError;
71 platforms = emacs.meta.platforms;
72 } // optionalAttrs ((args.src.meta.homepage or "") != "") {
73 homepage = args.src.meta.homepage;
77 // optionalAttrs (emacs.withNativeCompilation or false) {
79 addEmacsNativeLoadPath = args.addEmacsNativeLoadPath or true;
82 # Besides adding the output directory to the native load path, make sure
83 # the current package's elisp files are in the load path, otherwise
84 # (require 'file-b) from file-a.el in the same package will fail.
85 mkdir -p $out/share/emacs/native-lisp
86 source ${./emacs-funcs.sh}
89 # package-activate-all is used to activate packages. In other builder
90 # helpers, package-initialize is used for this purpose because
91 # package-activate-all is not available before Emacs 27.
92 find $out/share/emacs -type f -name '*.el' -not -name ".dir-locals.el" -print0 \
93 | xargs --verbose -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \
96 -f package-activate-all \
97 --eval '(setq native-comp-eln-load-path (cdr native-comp-eln-load-path))' \
98 --eval '(let ((default-directory \"$out/share/emacs/site-lisp\")) (normal-top-level-add-subdirs-to-load-path))' \
99 --eval '(setq large-file-warning-threshold nil)' \
100 --eval '(setq byte-compile-error-on-warn ${if finalAttrs.turnCompilationWarningToError then "t" else "nil"})' \
101 -f batch-native-compile {} \
102 || exit ${if finalAttrs.ignoreCompilationError then "0" else "\\$?"}"