Advice doom-profile-init-file to use our profile

`doom-start` locates the profile init file relative to
`doom-profile-dir` when running interactively, which we customize (either
directly or by setting `doom-profile-data-dir`). But when running
noninteractively, it uses `doom-profile-init-file`, which always loads
relative to `doom-data-dir`.

We cannot point `doom-data-dir` into the store, so this breaks us.

Work around it by advicing `doom-profile-data-dir` to locate the init
file relative to `doom-profile-dir` too. Try to make this more safe by
erroring out if called on a non-default profile.

All of this feels questionable, but I really want `doom doctor` to
work...
This commit is contained in:
Marien Zwart 2024-04-28 20:11:51 +10:00
parent 24ee7b6838
commit 6b8ff7b693
No known key found for this signature in database
2 changed files with 23 additions and 0 deletions

View file

@ -249,6 +249,7 @@ let
fi
substitute ${./init.el} $out/doomdir/init.el \
--subst-var-by maybe-set-profile-dir "$setProfile" \
--subst-var-by profile-name "${profileName}" \
--subst-var-by user-init "${doomDir}/init.el" \
--subst-var-by straight-base-dir $out
ln -sf ${doomIntermediates}/packages.el $out/doomdir/

22
init.el
View file

@ -36,6 +36,28 @@ it. Just skip it entirely."
(after! doom-packages
(setq straight-base-dir "@straight-base-dir@"))
(defadvice! unstraightened-profile-init-file (&optional profile-id version)
"Return unstraightened's profile init file.
`doom-profile-init-file' locates the profile relative to `doom-data-dir', but
nix-doom-emacs-unstraightened keeps its profile in a different location.
Override `doom-profile-init-file' to confirm it is called to get the default
or unstraightened profile (erroring out otherwise), then return the custom path.
Returning the unstraightened profile if the default profile is
requested makes `doom doctor' work."
:override #'doom-profile-init-file
(let ((my-profile "@profile-name@"))
(unless (or (null profile-id)
(and (not (string-empty-p my-profile))
(string-equal profile-id my-profile)))
(error "Accessing other profiles from Unstraightened is unsupported."))
(unless (null version)
(error
"Accessing other profile versions from Unstraightened is unsupported."))
(file-name-concat
doom-profile-dir (format "init.%d.elc" emacs-major-version))))
;; TODO: remove if Doom accepts https://github.com/doomemacs/doomemacs/pull/7849
(defadvice! nix-doom-configs-without-git (package)
"Override to use ripgrep instead of git."