From 13e80707b2e8f0f707f81791b06e4a5e0cdf246d Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Mon, 16 Sep 2024 13:15:02 +0800 Subject: [PATCH 1/2] emacs: make sure native compilation output dir is in $out Native compilation output dir is the first writable one specified by native-comp-eln-load-path[1]. The first[2] dir in native-comp-eln-load-path is in $HOME. In the nix build sandbox, $HOME normally does not exist so this first dir is not writable. The second dir is in $out and thus is writable. So it is chosen as the native compilation output dir. Some packages, such as auctex[3], needs a writable $HOME when being compiled. To avoid compilation error, it is necessary to create a writable $HOME. To make sure native compilation output dir is in $out, we can make the first dir of native-comp-eln-load-path, the one in $HOME, read-only. Or we can explicitly choose the second dir. This patch use the second explicit method. [1]: (info "(elisp) Native-Compilation Functions") [2]: https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/startup.el?id=f27553c30a772a0103d2e6762e4d7f588f302e4b#n615 [3]: https://hydra.nixos.org/build/271252219/nixlog/1 --- pkgs/applications/editors/emacs/build-support/generic.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/applications/editors/emacs/build-support/generic.nix b/pkgs/applications/editors/emacs/build-support/generic.nix index d22e6495c1d2..9f1b2308cc43 100644 --- a/pkgs/applications/editors/emacs/build-support/generic.nix +++ b/pkgs/applications/editors/emacs/build-support/generic.nix @@ -90,6 +90,7 @@ libBuildHelper.extendMkDerivation' stdenv.mkDerivation (finalAttrs: | xargs --verbose -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \ "emacs \ --batch \ + --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"})' \ -f batch-native-compile {} \ From e623501bd1434334c124812557a35ac737105513 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Tue, 17 Sep 2024 00:30:32 +0800 Subject: [PATCH 2/2] emacs: add elisp package override helper mkHome Some packages, such as auctex[1], need a writable $HOME when being compiled. [1]: https://hydra.nixos.org/build/271252219/nixlog/1 --- .../emacs/elisp-packages/lib-override-helper.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/applications/editors/emacs/elisp-packages/lib-override-helper.nix b/pkgs/applications/editors/emacs/elisp-packages/lib-override-helper.nix index 74d185641e3d..fb1f412299f7 100644 --- a/pkgs/applications/editors/emacs/elisp-packages/lib-override-helper.nix +++ b/pkgs/applications/editors/emacs/elisp-packages/lib-override-helper.nix @@ -25,4 +25,14 @@ rec { broken = true; }; }); + + mkHome = + pkg: + pkg.overrideAttrs (previousAttrs: { + preInstall = + '' + HOME=$(mktemp -d) + '' + + previousAttrs.preInstall or ""; + }); }