From 88accc0c92639355ce8a1c62cfaac0e07bc09de9 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Sun, 27 Sep 2026 18:55:45 +0800 Subject: [PATCH] emacs: use PATH instead of exec-path to expose wrapped binaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (info "(elisp) Subprocess Creation") says: > Generally, you should not modify ‘exec-path’ directly. Instead, > ensure that your ‘PATH’ environment variable is set appropriately > before starting Emacs. Trying to modify ‘exec-path’ independently > of ‘PATH’ can lead to confusing results. One example of "confusing results" can be found in envrc[1]. This patch follows that recommendation of Emacs lisp manual. In addition, we added tests for PATH and exec-path. [1]: https://github.com/purcell/envrc/issues/9 --- .../wrapper-test/with-packages.el | 27 +++++++++++++++++-- .../editors/emacs/build-support/wrapper.nix | 5 ++-- .../editors/emacs/build-support/wrapper.sh | 5 ++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/editors/emacs/build-support/wrapper-test/with-packages.el b/pkgs/applications/editors/emacs/build-support/wrapper-test/with-packages.el index 9f0ed7920c2a..30735966656d 100644 --- a/pkgs/applications/editors/emacs/build-support/wrapper-test/with-packages.el +++ b/pkgs/applications/editors/emacs/build-support/wrapper-test/with-packages.el @@ -41,6 +41,13 @@ which is generated by nix when building this elisp package." (defun with-packages-unwrapped-site-start-is-loaded () (fboundp 'nix--profile-paths)) +(defun with-packages-eval-in-sub-emacs (form) + "Evaluate FORM in a subprocess Emacs and return its result." + (pcase-exhaustive + (process-lines "emacs" "--batch" + "--eval" (format "(prin1 %S)" form)) + (`(,result) (read result)))) + ;;;; Tests that can be run in a batch Emacs (ert-deftest with-packages-requested-packages-are-available () @@ -71,8 +78,24 @@ which is generated by nix when building this elisp package." (ert-deftest with-packages-unwrapped-site-start-is-loaded () (should (with-packages-unwrapped-site-start-is-loaded))) -(ert-deftest with-packages-bin-dirs-of-requested-packages-are-added-to-exec-path () - (should (executable-find "cowsay"))) +(ert-deftest with-packages-binaries-of-requested-packages-are-available () + (ert-info ("find binary via PATH") + (should (equal (call-process-shell-command "cowsay") 0))) + (ert-info ("find binary via exec-path") + (should (executable-find "cowsay"))) + (ert-info ("each item is unique") + (cl-flet ((item-should-be-unique (items) + (should (equal items + (cl-remove-duplicates items :test #'string=))))) + (ert-info ("PATH of this Emacs") + (item-should-be-unique (parse-colon-path (getenv "PATH")))) + (ert-info ("PATH of sub-Emacs") + (item-should-be-unique + (parse-colon-path (with-packages-eval-in-sub-emacs '(getenv "PATH"))))) + (ert-info ("exec-path of this Emacs") + (item-should-be-unique exec-path)) + (ert-info ("exec-path of sub-Emacs") + (item-should-be-unique (with-packages-eval-in-sub-emacs 'exec-path)))))) (ert-deftest with-packages-tree-sitter-dir-is-added-to-treesit-extra-load-path () (skip-unless (treesit-available-p)) diff --git a/pkgs/applications/editors/emacs/build-support/wrapper.nix b/pkgs/applications/editors/emacs/build-support/wrapper.nix index 782fa7681974..1f9fbb240c5a 100644 --- a/pkgs/applications/editors/emacs/build-support/wrapper.nix +++ b/pkgs/applications/editors/emacs/build-support/wrapper.nix @@ -171,9 +171,6 @@ runCommand (lib.appendToName "with-packages" emacs).name cat >"$siteStart" <