From b5e8dbeaa13fc7ba96b96f4614efc7215e8c2600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Vask=C3=B3?= Date: Sat, 26 Sep 2020 13:31:09 +0200 Subject: [PATCH 1/4] output formating: use nix variables for reusability in other stages --- default.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/default.nix b/default.nix index 5b5cb2f..2151ffc 100644 --- a/default.nix +++ b/default.nix @@ -91,6 +91,12 @@ let ''; }; + fmt = { + reset=''\\033[0m''; + bold=''\\033[1m''; + green=''\\033[32m''; + }; + # Bundled version of `emacs-overlay` emacs-overlay = import (lock "emacs-overlay") pkgs pkgs; @@ -187,14 +193,10 @@ let ])); build-summary = writeShellScript "build-summary" '' - BOLD=\\033[1m - GREEN=\\033[32m - RESET=\\033[0m - - printf "\n''${GREEN}Successfully built nix-doom-emacs!''${RESET}\n" - printf "''${BOLD} ==> doom-emacs is installed to ${doom-emacs}''${RESET}\n" - printf "''${BOLD} ==> private configuration is installed to ${doomDir}''${RESET}\n" - printf "''${BOLD} ==> Dependencies are installed to ${doomLocal}''${RESET}\n" + printf "\n${fmt.green}Successfully built nix-doom-emacs!${fmt.reset}\n" + printf "${fmt.bold} ==> doom-emacs is installed to ${doom-emacs}${fmt.reset}\n" + printf "${fmt.bold} ==> private configuration is installed to ${doomDir}${fmt.reset}\n" + printf "${fmt.bold} ==> Dependencies are installed to ${doomLocal}${fmt.reset}\n" ''; in emacs.overrideAttrs (esuper: 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 2/4] 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 From 566b674164cb845cc04b2d8928140a29825f035b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Vask=C3=B3?= Date: Sun, 27 Sep 2020 12:28:18 +0200 Subject: [PATCH 3/4] gccEmacs: add runtime writable eln cache location --- nix-integration.patch | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix-integration.patch b/nix-integration.patch index 649e4e1..e3007b7 100644 --- a/nix-integration.patch +++ b/nix-integration.patch @@ -26,11 +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." +@@ -276,7 +276,8 @@ 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-cache-dir "eln/")) + (add-to-list 'comp-eln-load-path (concat doom-local-dir "cache/eln/"))) (after! comp From b344cf066d96b234dab385075c7dc6926b5a79e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Vask=C3=B3?= Date: Sun, 27 Sep 2020 23:03:44 +0200 Subject: [PATCH 4/4] load `config.el` from outside of nix store That way a rebuild is not needed to pick up modifications from it --- default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 58fd73a..2faa99a 100644 --- a/default.nix +++ b/default.nix @@ -192,7 +192,11 @@ let mkdir -p $out cp -r ${doomPrivateDir}/* $out chmod u+w $out/config.el - cat $extraConfigPath >> $out/config.el + cat $extraConfigPath > $out/config.extra.el + cat > $out/config.el << EOF + (load "${builtins.toString doomPrivateDir}/config.el") + (load "$out/config.extra.el") + EOF ''; # Stage 5: catch-all wrapper capable to run doom-emacs even