From 23cf6b9884546f064382dc96baa541c0f15485e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Vask=C3=B3?= Date: Sat, 26 Sep 2020 00:05:12 +0200 Subject: [PATCH] support gccEmacs If built with gccEmacs, in `straight--native-compile-package` step tries to access $HOME because `comp-eln-load-path` contains "~/.emacs.d/eln-cache/". It errors on this as it is set to a readonly canary value of `/homeless-shellter` in the nix build sandbox. The workaround is twofold: * Ignore `kill-emacs` from optimization. It would result in eln file being written before doom sets up the load path outside of HOME. * The above solution doesn't help in the actual build phase because the worker processes compiling packages does not inherit this value but it is set in them at a later time. This causes the build to fail before `comp-eln-load-path` would be successfully overridden. Having a writable $HOME does not seem to produce any build output there hence the override and the check in `postInstall` to verify that the directory is indeed empty. The runtime value of `comp-eln-load-path` also had to be changed because it is by default is located under the volatile `doom-cache-dir` which is not a part of the derivation so the build time generated `.eln` files couldn't be loaded from that. References: #57 --- advice.el | 6 ++++++ default.nix | 17 +++++++++++++++++ nix-integration.patch | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/advice.el b/advice.el index 675b0fc..13682eb 100644 --- a/advice.el +++ b/advice.el @@ -7,6 +7,12 @@ ;;; have a properly configured user home and environment. (setq package-check-signature nil) +;;; For gccEmacs compatibility +(with-eval-after-load "comp" + ;; The advice for 'kill-emacs would result in eln files being written before + ;; doom would set up proper load paths + (add-to-list 'comp-never-optimize-functions 'kill-emacs)) + (defun nix-straight-inhibit-kill-emacs (arg) (message "[nix-doom-emacs] Inhibiting (kill-emacs)")) diff --git a/default.nix b/default.nix index 2151ffc..58fd73a 100644 --- a/default.nix +++ b/default.nix @@ -94,6 +94,7 @@ let fmt = { reset=''\\033[0m''; bold=''\\033[1m''; + red=''\\033[31m''; green=''\\033[32m''; }; @@ -146,6 +147,22 @@ let preInstall = '' export DOOMDIR=${doomPrivateDir} export DOOMLOCALDIR=$out/ + + # Create a bogus $HOME directory because gccEmacs is known to require + # an existing home directory because the async worker process don't + # fully respect the value of 'comp-eln-load-path'. + export HOME=$(mktemp -d) + ''; + postInstall = '' + # If gccEmacs or anything would write in $HOME, fail the build. + if [[ -z "$(find $HOME -maxdepth 0 -empty)" ]]; then + printf "${fmt.red}${fmt.bold}ERROR:${fmt.reset} " + printf "${fmt.red}doom-emacs build resulted in files being written in "'$HOME'" of the build sandbox.\n" + printf "Contents of "'$HOME'":\n" + find $HOME + printf ${fmt.reset} + exit 33 + fi ''; }); diff --git a/nix-integration.patch b/nix-integration.patch index 8faafd9..649e4e1 100644 --- a/nix-integration.patch +++ b/nix-integration.patch @@ -26,3 +26,12 @@ index c8cfb0495..d8ed107bd 100644 "Directory for volatile local storage. Use this for files that change often, like cache files. Must end with a slash.") +@@ -276,7 +276,7 @@ config.el instead." + ;; Don't store eln files in ~/.emacs.d/eln-cache (they are likely to be purged + ;; when upgrading Doom). + (when (boundp 'comp-eln-load-path) +- (add-to-list 'comp-eln-load-path (concat doom-cache-dir "eln/"))) ++ (add-to-list 'comp-eln-load-path (concat doom-local-dir "cache/eln/"))) + + (after! comp + ;; HACK `comp-eln-load-path' isn't fully respected yet, because native