2019-07-07 13:32:00 +00:00
|
|
|
;; -*- lexical-binding: t; -*-
|
2018-01-04 10:16:35 +00:00
|
|
|
(defun nix--profile-paths ()
|
2019-07-07 13:32:00 +00:00
|
|
|
"Return a list of all paths in NIX_PROFILES.
|
|
|
|
The list is ordered from more-specific (the user profile) to the
|
2018-01-04 10:16:35 +00:00
|
|
|
least specific (the system profile)"
|
|
|
|
(reverse (split-string (or (getenv "NIX_PROFILES") ""))))
|
|
|
|
|
2022-02-23 01:55:58 +00:00
|
|
|
;;; Extend `load-path' to search for elisp files in subdirectories of all folders in `NIX_PROFILES'.
|
|
|
|
;;; Non-Nix distros have similar logic in /usr/share/emacs/site-lisp/subdirs.el.
|
|
|
|
;;; See https://www.gnu.org/software/emacs/manual/html_node/elisp/Library-Search.html
|
2023-08-26 01:20:29 +00:00
|
|
|
(dolist (profile (reverse (nix--profile-paths)))
|
|
|
|
;; `directory-file-name' is important to add sub dirs to the right place of `load-path'
|
|
|
|
;; see the source code of `normal-top-level-add-to-load-path'
|
|
|
|
(let ((default-directory (directory-file-name
|
|
|
|
(expand-file-name "share/emacs/site-lisp/" profile))))
|
2022-02-23 01:55:58 +00:00
|
|
|
(when (file-exists-p default-directory)
|
|
|
|
(setq load-path (cons default-directory load-path))
|
|
|
|
(normal-top-level-add-subdirs-to-load-path))))
|
2018-01-04 10:48:25 +00:00
|
|
|
|
emacsWithPackages: don't tell sub-Emacs about pkgs
If I'm running an Emacs executable from emacsWithPackages as my main
programming environment, and I'm hacking on Emacs, or the Emacs
packaging in Nixpkgs, or whatever, I don't want the Emacs packages
from the wrapper to show up in the load path of that child Emacs. It
results in differing behaviour depending on whether the child Emacs is
run from Emacs or from, for example, an external terminal emulator,
which is very surprising.
To avoid this, pass another environment variable containing the
wrapper site-lisp path, and use that value to remove the corresponding
entry in EMACSLOADPATH, so it won't be propagated to child Emacsen.
2020-12-07 18:53:54 +00:00
|
|
|
;;; Remove wrapper site-lisp from EMACSLOADPATH so it's not propagated
|
|
|
|
;;; to any other Emacsen that might be started as subprocesses.
|
|
|
|
(let ((wrapper-site-lisp (getenv "emacsWithPackages_siteLisp"))
|
|
|
|
(env-load-path (getenv "EMACSLOADPATH")))
|
|
|
|
(when wrapper-site-lisp
|
|
|
|
(setenv "emacsWithPackages_siteLisp" nil))
|
|
|
|
(when (and wrapper-site-lisp env-load-path)
|
|
|
|
(let* ((env-list (split-string env-load-path ":"))
|
|
|
|
(new-env-list (delete wrapper-site-lisp env-list)))
|
|
|
|
(setenv "EMACSLOADPATH" (when new-env-list
|
|
|
|
(mapconcat 'identity new-env-list ":"))))))
|
2015-03-07 11:03:26 +00:00
|
|
|
|
2020-11-16 19:24:29 +00:00
|
|
|
(let ((wrapper-site-lisp (getenv "emacsWithPackages_siteLispNative"))
|
|
|
|
(env-load-path (getenv "EMACSNATIVELOADPATH")))
|
|
|
|
(when wrapper-site-lisp
|
|
|
|
(setenv "emacsWithPackages_siteLispNative" nil))
|
|
|
|
(when (and wrapper-site-lisp env-load-path)
|
|
|
|
(let* ((env-list (split-string env-load-path ":"))
|
|
|
|
(new-env-list (delete wrapper-site-lisp env-list)))
|
|
|
|
(setenv "EMACSNATIVELOADPATH" (when new-env-list
|
|
|
|
(mapconcat 'identity new-env-list ":"))))))
|
|
|
|
|
|
|
|
;;; Set up native-comp load path.
|
2023-08-26 06:25:11 +00:00
|
|
|
(when (featurep 'native-compile)
|
2020-11-16 19:24:29 +00:00
|
|
|
;; Append native-comp subdirectories from `NIX_PROFILES'.
|
2023-08-26 06:52:13 +00:00
|
|
|
;; Emacs writes asynchronous native-compilation files to the first writable directory[1].
|
|
|
|
;; At this time, (car native-comp-eln-load-path) is a writable one in `user-emacs-directory'[2].
|
|
|
|
;; So we keep that one unchanged.
|
|
|
|
;; [1]: info "(elisp) Native-Compilation Variables"
|
|
|
|
;; [2]: https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/startup.el?id=3685387e609753293c4518be75e77c659c3b2d8d#n601
|
2021-05-06 19:44:43 +00:00
|
|
|
(setq native-comp-eln-load-path
|
2023-08-26 06:52:13 +00:00
|
|
|
(append (list (car native-comp-eln-load-path))
|
|
|
|
(mapcar (lambda (profile-dir)
|
2020-11-16 19:24:29 +00:00
|
|
|
(concat profile-dir "/share/emacs/native-lisp/"))
|
|
|
|
(nix--profile-paths))
|
2023-08-26 06:52:13 +00:00
|
|
|
(cdr native-comp-eln-load-path))))
|
2020-11-16 19:24:29 +00:00
|
|
|
|
2015-03-07 11:03:26 +00:00
|
|
|
;;; Make `woman' find the man pages
|
2019-07-07 13:32:00 +00:00
|
|
|
(defvar woman-manpath)
|
2015-03-07 11:03:26 +00:00
|
|
|
(eval-after-load 'woman
|
|
|
|
'(setq woman-manpath
|
2018-01-04 10:16:35 +00:00
|
|
|
(append (mapcar (lambda (x) (concat x "/share/man/"))
|
|
|
|
(nix--profile-paths))
|
2015-03-07 11:03:26 +00:00
|
|
|
woman-manpath)))
|
|
|
|
|
2016-09-27 19:57:52 +00:00
|
|
|
;;; Make tramp work for remote NixOS machines
|
2019-07-07 13:32:00 +00:00
|
|
|
(defvar tramp-remote-path)
|
2023-09-07 04:03:47 +00:00
|
|
|
(eval-after-load 'tramp
|
2018-01-04 10:16:35 +00:00
|
|
|
;; TODO: We should also add the other `NIX_PROFILES' to this path.
|
|
|
|
;; However, these are user-specific, so we would need to discover
|
|
|
|
;; them dynamically after connecting via `tramp'
|
2023-08-31 17:45:09 +00:00
|
|
|
'(progn
|
|
|
|
(add-to-list 'tramp-remote-path "/run/current-system/sw/bin")
|
|
|
|
(add-to-list 'tramp-remote-path "/run/wrappers/bin")))
|
2016-09-27 19:57:52 +00:00
|
|
|
|
|
|
|
;;; C source directory
|
|
|
|
;;;
|
|
|
|
;;; Computes the location of the C source directory from the path of
|
|
|
|
;;; the current file:
|
|
|
|
;;; from: /nix/store/<hash>-emacs-<version>/share/emacs/site-lisp/site-start.el
|
|
|
|
;;; to: /nix/store/<hash>-emacs-<version>/share/emacs/<version>/src/
|
2019-07-07 13:32:00 +00:00
|
|
|
(defvar find-function-C-source-directory)
|
2016-09-27 19:57:52 +00:00
|
|
|
(let ((emacs
|
2018-01-04 10:16:35 +00:00
|
|
|
(file-name-directory ; .../emacs/
|
|
|
|
(directory-file-name ; .../emacs/site-lisp
|
|
|
|
(file-name-directory load-file-name)))) ; .../emacs/site-lisp/
|
2016-09-27 19:57:52 +00:00
|
|
|
(version
|
|
|
|
(file-name-as-directory
|
2020-11-15 18:32:05 +00:00
|
|
|
emacs-version))
|
2016-09-27 19:57:52 +00:00
|
|
|
(src (file-name-as-directory "src")))
|
|
|
|
(setq find-function-C-source-directory (concat emacs version src)))
|