nix-doom-emacs-unstraightened/cli2.el
Marien Zwart d05ecd9b19
Fix autoloads load order
Trying to start doom-example after enabling `scheme +guile` confirmed we
have at least one package (geiser-guile) that requires its dependency's
autoloads are loaded before its own are.

Fix it by assuming `package-activated-list` is in reverse order of
activation. That behavior is (as far as I could find) not documented,
but sufficiently obvious it seems safe enough to rely on it.
2024-04-07 20:40:12 +10:00

71 lines
2.9 KiB
EmacsLisp

;;; cli.el -*- lexical-binding: t; -*-
;; We skip Doom's normal install and initialization.
(require 'straight)
(defadvice! nix-doom-skip-core-packages (&rest _)
"HACK: don't install straight and core packages.
`doom-initialize-core-packages' would no-op out if
`straight-recipe-repositories' is set, but we do not want to set
it. Just skip it entirely."
:override #'doom-initialize-core-packages
t)
(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 `((,profile-name
(user-emacs-directory . ,doom-emacs-dir)
(doom-profile-data-dir . ,profile-directory)
("DOOMDIR" . ,profile-doom-dir)))))
(doom-profiles-save new-profiles)))
;; Doom runs this with package.el activated, but suppresses activation during
;; normal startup. Store the side effects of activation in the profile to avoid
;; (slow) package activation during normal startup.
;;
;; package-activate-1 does:
;; - Load autoloads. Duplicated by generate-unstraightened-autoloads.
;; - Add to load-path. Doom already stores load-path.
;; - Add Info node. TODO.
;; - Add name to package-activated-list. Stored below.
(defun generate-unstraightened-autoloads ()
"Like doom-profile--generate-package-autoloads but for package.el."
(doom-autoloads--scan
(mapcar (lambda (s)
(format "%s.el"
(package--autoloads-file-name (package-get-descriptor s))))
;; Packages are (currently...) pushed onto package-activated-list as
;; they are activated. Reverse the list here so packages activated
;; first get their autoloads loaded first.
;;
;; An example package that requires this is geiser-guile: it calls
;; geiser-activate-implementation from autoloads, requiring geiser's
;; autoloads are loaded first.
(nreverse
(seq-difference package-activated-list
(mapcar #'intern-soft
doom-autoloads-excluded-packages))))
doom-autoloads-excluded-files
'literal))
(add-to-list
'doom-profile-generators
'("90-loaddefs-unstraightened.auto.el" . generate-unstraightened-autoloads))
(add-to-list 'doom-autoloads-cached-vars 'package-activated-list)
(defcli! build-profile-for-nix-build ()
"Write a Doom profile."
;; HACK: this initializes enough of straight (particularly
;; straight--build-cache, which doom-profile--generate-package-autoloads hits)
;; to make Doom work.
;;
;; TODO: remove doom-profile--generate-package-autoloads?
;; Because there are no straight-built packages, it generates an empty file.
(straight-prune-build-cache)
(doom-profile-generate))