From ca353afab5e8959737c9236337509403fcded7e6 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sat, 22 Oct 2022 15:37:35 +0100 Subject: [PATCH] Fix early-init.patch --- default.nix | 11 +++++----- patches/early-init.patch | 44 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/default.nix b/default.nix index 77f7f9a3..83b5a7de 100644 --- a/default.nix +++ b/default.nix @@ -194,17 +194,14 @@ let src = doomSrc; patches = [ - (substituteAll { - src = ./patches/early-init.patch; - doom = src; - }) + ./patches/early-init.patch ./patches/move-doom-dir-paths-to-HOME.patch ]; buildPhase = '' - patchShebangs bin # Remove the windows wrapper for the CLI so the build doesn't fail rm bin/doom.cmd + patchShebangs bin ''; installPhase = '' mkdir -p $out @@ -247,7 +244,9 @@ let # startup performance emacs-dir = runCommand "emacs-dir" { } '' mkdir -p $out - cp ${doom-emacs}/early-init.el $out + cat > $out/early-init.el << EOF + (load "${doom-emacs}/early-init.el") + EOF cat > $out/init.el << EOF (load "default.el") EOF diff --git a/patches/early-init.patch b/patches/early-init.patch index 82d89a2d..6dc5fad7 100644 --- a/patches/early-init.patch +++ b/patches/early-init.patch @@ -1,8 +1,8 @@ diff --git a/early-init.el b/early-init.el -index c6e6b4d68..16d99a785 100644 +index c6e6b4d68..4d34ab0a9 100644 --- a/early-init.el +++ b/early-init.el -@@ -60,20 +60,7 @@ +@@ -60,20 +60,8 @@ (profile (or (cadr (member "--profile" command-line-args)) (getenv-internal "DOOMPROFILE")))) (if (null profile) @@ -20,7 +20,45 @@ index c6e6b4d68..16d99a785 100644 - ;; FIX: To prevent "invalid option" errors later. - (push (cons "--init-directory" (lambda (_) (pop argv))) command-switch-alist) - (setq user-emacs-directory (expand-file-name init-dir)))) -+ (setq user-emacs-directory "@doom@") ++ (setq user-emacs-directory ++ (file-name-directory (file-truename load-file-name))) ;; FIX: Discard the switch to prevent "invalid option" errors later. (push (cons "--profile" (lambda (_) (pop argv))) command-switch-alist) ;; Running 'doom sync' or 'doom profile sync' (re)generates a light +@@ -105,34 +93,8 @@ + ;; I avoid `load's NOERROR argument because other, legitimate errors + ;; (like permission or IO errors) should not be suppressed or + ;; interpreted as "this is not a Doom config". +- (condition-case _ +- ;; Load the heart of Doom Emacs. +- (load (expand-file-name "lisp/doom" user-emacs-directory) +- nil (not init-file-debug) nil 'must-suffix) +- ;; Failing that, assume that we're loading a non-Doom config. +- (file-missing +- ;; HACK: `startup--load-user-init-file' resolves $EMACSDIR from a +- ;; lexically bound `startup-init-directory', which means changes +- ;; to `user-emacs-directory' won't be respected when loading +- ;; $EMACSDIR/init.el, so I force it to: +- (define-advice startup--load-user-init-file (:filter-args (args) reroute-to-profile) +- (list (lambda () (expand-file-name "init.el" user-emacs-directory)) +- nil (nth 2 args))) +- ;; Set `user-init-file' for the `load' call further below, and do so +- ;; here while our `file-name-handler-alist' optimization is still +- ;; effective (benefits `expand-file-name'). BTW: Emacs resets +- ;; `user-init-file' and `early-init-file' after this file is loaded. +- (setq user-init-file (expand-file-name "early-init" user-emacs-directory)) +- ;; COMPAT: I make no assumptions about the config we're going to +- ;; load, so undo this file's global side-effects. +- (setq load-prefer-newer t) +- ;; PERF: But make an exception for `gc-cons-threshold', which I +- ;; think all Emacs users and configs will benefit from. Still, +- ;; setting it to `most-positive-fixnum' is dangerous if downstream +- ;; does not reset it later to something reasonable, so I use 16mb +- ;; as a best fit guess. It's better than Emacs' 80kb default. +- (setq gc-cons-threshold (* 16 1024 1024)) +- nil))) ++ (load (expand-file-name "lisp/doom" user-emacs-directory) ++ nil (not init-file-debug) nil 'must-suffix)) + ;; ...But if Doom loaded then continue as normal. + (doom-require (if noninteractive 'doom-cli 'doom-start)))) +