@@ -1,6 +1,6 @@
11# generic builder for Emacs packages
22
3−{ lib, stdenv, emacs, texinfo, ... }:
3+{ lib, stdenv, emacs, texinfo, writeText, ... }:
44
55with lib;
66
@@ -49,7 +49,19 @@ stdenv.mkDerivation ({
4949 propagatedBuildInputs = packageRequires;
5050 propagatedUserEnvPkgs = packageRequires;
5151
52− setupHook = ./setup-hook.sh;
52+ setupHook = writeText "setup-hook.sh" ''
53+ source ${./emacs-funcs.sh}
54+
55+ if [[ ! -v emacsHookDone ]]; then
56+ emacsHookDone=1
57+
58+ # If this is for a wrapper derivation, emacs and the dependencies are all
59+ # run-time dependencies. If this is for precompiling packages into bytecode,
60+ # emacs is a compile-time dependency of the package.
61+ addEnvHooks "$hostOffset" addEmacsVars
62+ addEnvHooks "$targetOffset" addEmacsVars
63+ fi
64+ '';
5365
5466 doCheck = false;
5567
@@ -63,9 +75,16 @@ stdenv.mkDerivation ({
6375 addEmacsNativeLoadPath = true;
6476
6577 postInstall = ''
78+ # Besides adding the output directory to the native load path, make sure
79+ # the current package's elisp files are in the load path, otherwise
80+ # (require 'file-b) from file-a.el in the same package will fail.
81+ mkdir -p $out/share/emacs/native-lisp
82+ source ${./emacs-funcs.sh}
83+ addEmacsVars "$out"
84+
6685 find $out/share/emacs -type f -name '*.el' -print0 \
6786 | xargs -0 -n 1 -I {} -P $NIX_BUILD_CORES sh -c \
68− "emacs --batch --eval=\"(add-to-list 'comp-eln-load-path \\\"$out/share/emacs/native-lisp/\\\")\" -f batch-native-compile {} || true"
87+ "emacs --batch -f batch-native-compile {} || true"
6988 '';
7089}
7190