Skip to content

Commit

Permalink
Leave the user init.el alone
Browse files Browse the repository at this point in the history
Instead of replacing init.el in DOOMDIR with our init.el and loading the
original from there, load our init.el from the profile init file (and
explicitly from build-profile).

Now that Doom loads the user init.el from the profile init file, this
only slightly changes load order (it should just swap our init.el and
the user init.el).

Benefit for the user is that they can find their init.el normally using
things like doom/find-file-in-private-config. Benefit for us is that
init.el no longer gets anything substituted into it, it is loaded as-is.
  • Loading branch information
marienz committed Nov 21, 2024
1 parent fe642df commit 07aa2a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 1 addition & 3 deletions build-helpers/build-doom-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ ln -s $doomDir/* $out/doomdir/
if ! [[ -e $out/doomdir/snippets ]]; then
mkdir $out/doomdir/snippets
fi
rm $out/doomdir/init.el
substitute $initEl $out/doomdir/init.el \
--subst-var-by userInit "$doomDir/init.el"
ln -sf $doomIntermediates/packages.el $out/doomdir/
export DOOMDIR=$out/doomdir

Expand All @@ -36,6 +33,7 @@ $runtimeShell $doomSource/bin/doomscript $buildProfileLoader \
export HOME="$PWD/home"
export DOOMPROFILE="$profileName";
$runtimeShell $doomSource/bin/doomscript $buildProfile \
-i $initEl \
-l $deps/share/emacs/site-lisp

# Similar to audit-tmpdir.sh in nixpkgs.
Expand Down
24 changes: 17 additions & 7 deletions build-helpers/build-profile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

;; Set from run!
(defvar site-lisp)
(defvar init-file)

(defun generate-unstraightened-init-load ()
"Load unstraightened init.el."
`((defun unstraightened--startup-init ()
(doom-load ,init-file))))

(add-to-list
'doom-profile-generators
'("00-unstraightened-init.auto.el" generate-unstraightened-init-load unstraightened--startup-init))

(defun generate-nix-autoloads ()
"Pull in autoloads for non-ELPA emacsWithPackages dependencies."
Expand Down Expand Up @@ -87,16 +97,16 @@
(add-to-list 'doom-autoloads-cached-vars 'package-activated-list)

(defcli! build-profile
((site-lisp ("-l" dir) "site-lisp directory to load autoloads from"))
((site-lisp ("-l" dir) "site-lisp directory to load autoloads from")
(init-file ("-i" file) "unstraightened init.el"))
"Write a Doom profile."
;; This also loads our generated profile's init.el. We need that both to get
;; the profile right and to load the advice to make Doom not install straight.
;; This also loads our generated profile's init.el (so we include the right
;; packages in the profile).
(doom-modules-initialize)
;; Load our init.el, so we can load straight without hitting
;; doom-initialize-packages / doom-initialize-core-packages.
(doom-load init-file)
;; Now load straight (straight-prune-build-cache is not autoloaded).
;;
;; (Doom may call doom-initialize-packages / doom-initialize-core-packages
;; from an after-load hook on straight, so we want to do this after we
;; installed our advice of doom-initialize-core-packages above.)
(require 'straight)
;; Trigger a write of straight's build cache (which we write into the profile
;; and load again later).
Expand Down
8 changes: 3 additions & 5 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.

;; Extra initialization code for nix-doom-emacs-unstraightened, run before the
;; normal `init.el'.
;; Extra initialization code for nix-doom-emacs-unstraightened.
;;
;; Loaded from the profile init file.

(defadvice! nix-doom-skip-core-packages (&rest _)
"HACK: don't install straight and core packages.
Expand All @@ -42,6 +43,3 @@ it. Just skip it entirely."
(prin1-to-string `(progn
(setq doom-profile-data-dir ,doom-profile-data-dir)
,(read flycheck-emacs-lisp-check-form))))

;; Load the user's init.el.
(load "@userInit@" nil 'nomessage)

0 comments on commit 07aa2a8

Please sign in to comment.