1 # generic builder for Emacs packages
3 { lib, stdenv, emacs, texinfo, writeText, gcc, ... }:
16 platforms = emacs.meta.platforms;
17 } // lib.optionalAttrs ((args.src.meta.homepage or "") != "") {
18 homepage = args.src.meta.homepage;
22 stdenv.mkDerivation (finalAttrs: ({
23 name = "emacs-${pname}-${finalAttrs.version}";
28 # keep original source filename without the hash
29 local filename=$(basename "$curSrc")
30 filename="''${filename:33}"
36 _defaultUnpack "$curSrc"
41 buildInputs = [emacs texinfo] ++ packageRequires ++ buildInputs;
42 propagatedBuildInputs = packageRequires;
43 propagatedUserEnvPkgs = packageRequires;
45 setupHook = writeText "setup-hook.sh" ''
46 source ${./emacs-funcs.sh}
48 if [[ ! -v emacsHookDone ]]; then
51 # If this is for a wrapper derivation, emacs and the dependencies are all
52 # run-time dependencies. If this is for precompiling packages into bytecode,
53 # emacs is a compile-time dependency of the package.
54 addEnvHooks "$hostOffset" addEmacsVars
55 addEnvHooks "$targetOffset" addEmacsVars
61 meta = defaultMeta // meta;
64 // lib.optionalAttrs (emacs.withNativeCompilation or false) {
66 LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";
68 nativeBuildInputs = [ gcc ];
70 addEmacsNativeLoadPath = true;
73 # Besides adding the output directory to the native load path, make sure
74 # the current package's elisp files are in the load path, otherwise
75 # (require 'file-b) from file-a.el in the same package will fail.
76 mkdir -p $out/share/emacs/native-lisp
77 source ${./emacs-funcs.sh}
80 find $out/share/emacs -type f -name '*.el' -print0 \
81 | xargs -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \
82 "emacs --batch --eval '(setq large-file-warning-threshold nil)' -f batch-native-compile {} || true"
86 // removeAttrs args [ "buildInputs" "packageRequires" "meta" ]))