nix-doom-emacs-unstraightened/build-helpers/build-profile
Marien Zwart fa6fe4cf93
Load non-packages.el autoloads
We were only pulling in autoloads files for packages installed via
packages.el. This was not that noticeable because all pinned packages
without custom derivations end up installed that way, but it does affect
extra packages (including the one pointed out in #11).

Try to fix this by including autoloads files in the top-level site-lisp
directory from emacsWithPackages.
2024-06-22 13:30:32 +10:00

83 lines
3.3 KiB
Text
Executable file

#!/usr/bin/env doomscript
;; -*- lexical-binding: t; -*-
;; Copyright 2024 Google LLC
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;; We skip Doom's normal install and initialization.
(require 'straight)
;; Set from run!
(defvar site-lisp)
(defun generate-nix-autoloads ()
"Pull in autoloads for non-ELPA emacsWithPackages dependencies."
(let (filenames)
(dolist (filename (directory-files site-lisp))
(when (string-suffix-p "-autoloads.el" filename)
(push (expand-file-name filename site-lisp) filenames)))
(doom-autoloads--scan filenames doom-autoloads-excluded-files 'literal)))
(add-to-list
'doom-profile-generators
'("80-loaddefs-nix.auto.el" . generate-nix-autoloads))
;; 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. Doom already stores Info-directory-list.
;; - 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
((site-lisp ("-l" dir) "site-lisp directory to load autoloads from"))
"Write a Doom profile."
;; Load our generated profile's init.el. Both to get the profile right and to
;; load the advice to make Doom not install straight.
(load! doom-module-init-file doom-user-dir t)
;; Trigger a write of straight's build cache (which we write into the profile
;; and load again later).
(straight-prune-build-cache)
(doom-profile-generate))
(run! "build-profile" (cdr (member "--" argv)))