diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index eb37809f8..83906b711 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -1601,7 +1601,7 @@ For more about modules and flags, see `doom!'." ;;; `doom-package' (cl-defmacro package! - (name &rest plist &key built-in recipe ignore _type _pin _disable) + (name &rest plist &key built-in recipe ignore _type _pin _disable _env) "Declares a package and how to install it (if applicable). This macro is declarative and does not load nor install packages. It is used to @@ -1638,6 +1638,9 @@ Accepts the following properties: inform help commands like `doom/help-packages' that this is a built-in package. If set to 'prefer, the package will not be installed if it is already provided by Emacs. + :env ALIST + Parameters and envvars to set while the package is building. If these values + change, the package will be rebuilt on next 'doom sync'. Returns t if package is successfully registered, and nil if it was disabled elsewhere." diff --git a/lisp/lib/packages.el b/lisp/lib/packages.el index 5d3f8b982..6eb260577 100644 --- a/lisp/lib/packages.el +++ b/lisp/lib/packages.el @@ -965,8 +965,14 @@ Must be run from a magit diff buffer." (if-let* ((built (doom-packages--with-recipes recipes (package local-repo recipe) (let ((repo-dir (straight--repos-dir (or local-repo package))) - (build-dir (straight--build-dir package))) + (build-dir (straight--build-dir package)) + (build-file ".doompackage")) (unless force-p + ;; Ensure packages w/ a changed :env are rebuilt + (when-let* ((plist (alist-get (intern package) doom-packages))) + (unless (equal (plist-get plist :env) + (doom-file-read (doom-path build-dir build-file) :by 'read :noerror t)) + (puthash package t straight--packages-to-rebuild))) ;; Ensure packages w/ outdated files/bytecode are rebuilt (let* ((build (if (plist-member recipe :build) (plist-get recipe :build) @@ -1005,7 +1011,25 @@ Must be run from a magit diff buffer." (print! (item "%s: pinned to %s") package pin) (when commit (print! (item "%s: checked out %s") package commit))))) - straight-vc-git-post-clone-hook))) + straight-vc-git-post-clone-hook)) + (straight-use-package-prepare-functions + (cons (lambda (package &rest _) + (when-let* ((plist (alist-get (intern package) doom-packages)) + (env (plist-get plist :env))) + (cl-loop for (var . val) in env + if (and (symbolp var) + (string-prefix-p "_" (symbol-name var))) + do (set-default var val) + else if (and (stringp var) val) + do (setenv var val)))) + straight-use-package-prepare-functions)) + (straight-use-package-post-build-functions + (cons (lambda (package &rest _) + (when-let* ((plist (alist-get (intern package) doom-packages)) + (env (plist-get plist :env))) + (with-temp-file (straight--build-file package build-file) + (prin1 env (current-buffer))))) + straight-use-package-post-build-functions))) (straight-use-package (intern package))) (error (signal 'doom-package-error (list package e)))))))) diff --git a/lisp/lib/profiles.el b/lisp/lib/profiles.el index 0ef3c7357..9d88116c6 100644 --- a/lisp/lib/profiles.el +++ b/lisp/lib/profiles.el @@ -61,6 +61,7 @@ Can be changed externally by setting $DOOMPROFILELOADFILE.") ;;; Profile storage variables (defvar doom-profile-generators '(("05-vars.auto.el" doom-profile--generate-vars doom--startup-vars) + ("20-package-envs.auto.el" doom-profile--generate-package-envs) ("80-loaddefs.auto.el" doom-profile--generate-loaddefs-doom doom--startup-loaddefs-doom) ("90-loaddefs-packages.auto.el" doom-profile--generate-loaddefs-packages doom--startup-loaddefs-packages) ("95-modules.auto.el" doom-profile--generate-load-modules doom--startup-modules)) @@ -422,6 +423,16 @@ caches them in `doom--profiles'. If RELOAD? is non-nil, refresh the cache." (mapcan #'doom-glob doom-autoloads-files)) nil))))) +(defun doom-profile--generate-package-envs () + (cl-loop for (_ . plist) in doom-packages + if (plist-get plist :env) + append (cl-loop for (var . val) in it + if (and (stringp var) val) + collect `(setenv ,var ,val) + else if (and (symbolp var) + (string-prefix-p "_" (symbol-name var))) + collect `(setq-default ,var ,val)))) + (defun doom-profile--generate-loaddefs-packages () `((defun doom--startup-loaddefs-packages () (let ((load-in-progress t))