Pass profile dirs as args instead of profiles.el

Writing profiles.el was borderline unreadable.
`doom-profiles-autodetect` was effectively just reading in the entire
file: accepting the paths we want in the profile as individual args and
putting them together on the Emacs side is easy enough.

Accidentally fixes a bug: `user-emacs-directory` should end in a
directory separator. We now get the right value for free by using the
path we're running Doom CLI out of.
This commit is contained in:
Marien Zwart 2024-03-31 17:28:34 +11:00
parent ffe2eae6cb
commit 0f80026223
No known key found for this signature in database
2 changed files with 11 additions and 13 deletions

10
cli2.el
View file

@ -12,9 +12,15 @@ it. Just skip it entirely."
:override #'doom-initialize-core-packages
t)
(defcli! build-profile-loader-for-nix-build ()
(defcli! build-profile-loader-for-nix-build
((profile-name ("-n" form) "Profile name.")
(profile-directory ("-p" dir) "Profile data directory.")
(profile-doom-dir ("-d" dir) "DOOMDIR"))
"Write Doom's profile loader."
(let ((new-profiles (doom-profiles-autodetect)))
(let ((new-profiles `((,profile-name
(user-emacs-directory . ,doom-emacs-dir)
(doom-profile-data-dir . ,profile-directory)
("DOOMDIR" . ,profile-doom-dir)))))
(doom-profiles-save new-profiles)))
(defcli! build-profile-for-nix-build ()

View file

@ -257,22 +257,14 @@ let
# Required to avoid Doom erroring out at startup.
nativeBuildInputs = [ git ];
} ''
mkdir $out
echo '
((${profileName} (user-emacs-directory . "${doomSource}")
(doom-profile-data-dir . "'$out'/profile")
("DOOMDIR" . "${finalDoomDir}")))
' > profiles.el
mkdir $out/loader
mkdir $out $out/loader $out/profile
export DOOMPROFILELOADFILE=$out/loader/init.el
export DOOMPROFILELOADPATH=$PWD/profiles.el
export DOOMLOCALDIR=$(mktemp -d)
# Prevent error on Emacs shutdown writing empty build cache.
mkdir $DOOMLOCALDIR/straight
${runtimeShell} ${doomSource}/bin/doom build-profile-loader-for-nix-build
${runtimeShell} ${doomSource}/bin/doom build-profile-loader-for-nix-build \
-n "${profileName}" -p "$out/profile" -d "${finalDoomDir}"
# With DOOMPROFILE set, doom-state-dir and friends are HOME-relative.
export HOME=$(mktemp -d)