nixos/kubernetes/kubelet: Fix sandbox image load on containerd 2.x (#364558)
[NixPkgs.git] / pkgs / applications / editors / emacs / site-start.el
blobc844e703e385fe21cd12d2a291b46100e6e1245b
1 ;; -*- lexical-binding: t; -*-
2 (defun nix--profile-paths ()
3 "Return a list of all paths in NIX_PROFILES.
4 The list is ordered from more-specific (the user profile) to the
5 least specific (the system profile)"
6 (reverse (split-string (or (getenv "NIX_PROFILES") ""))))
8 ;;; Extend `load-path' to search for elisp files in subdirectories of all folders in `NIX_PROFILES'.
9 ;;; Non-Nix distros have similar logic in /usr/share/emacs/site-lisp/subdirs.el.
10 ;;; See https://www.gnu.org/software/emacs/manual/html_node/elisp/Library-Search.html
11 (dolist (profile (reverse (nix--profile-paths)))
12 ;; `directory-file-name' is important to add sub dirs to the right place of `load-path'
13 ;; see the source code of `normal-top-level-add-to-load-path'
14 (let ((default-directory (directory-file-name
15 (expand-file-name "share/emacs/site-lisp/" profile))))
16 (when (file-exists-p default-directory)
17 (setq load-path (cons default-directory load-path))
18 (normal-top-level-add-subdirs-to-load-path))))
20 ;;; Remove wrapper site-lisp from EMACSLOADPATH so it's not propagated
21 ;;; to any other Emacsen that might be started as subprocesses.
22 (let ((wrapper-site-lisp (getenv "emacsWithPackages_siteLisp"))
23 (env-load-path (getenv "EMACSLOADPATH")))
24 (when wrapper-site-lisp
25 (setenv "emacsWithPackages_siteLisp" nil))
26 (when (and wrapper-site-lisp env-load-path)
27 (let* ((env-list (split-string env-load-path ":"))
28 (new-env-list (delete wrapper-site-lisp env-list)))
29 (setenv "EMACSLOADPATH" (when new-env-list
30 (mapconcat 'identity new-env-list ":"))))))
32 (let ((wrapper-site-lisp (getenv "emacsWithPackages_siteLispNative"))
33 (env-load-path (getenv "EMACSNATIVELOADPATH")))
34 (when wrapper-site-lisp
35 (setenv "emacsWithPackages_siteLispNative" nil))
36 (when (and wrapper-site-lisp env-load-path)
37 (let* ((env-list (split-string env-load-path ":"))
38 (new-env-list (delete wrapper-site-lisp env-list)))
39 (setenv "EMACSNATIVELOADPATH" (when new-env-list
40 (mapconcat 'identity new-env-list ":"))))))
42 ;;; Set up native-comp load path.
43 (when (featurep 'native-compile)
44 ;; Append native-comp subdirectories from `NIX_PROFILES'.
45 ;; Emacs writes asynchronous native-compilation files to the first writable directory[1].
46 ;; At this time, (car native-comp-eln-load-path) is a writable one in `user-emacs-directory'[2].
47 ;; So we keep that one unchanged.
48 ;; [1]: info "(elisp) Native-Compilation Variables"
49 ;; [2]: https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/startup.el?id=3685387e609753293c4518be75e77c659c3b2d8d#n601
50 (setq native-comp-eln-load-path
51 (append (list (car native-comp-eln-load-path))
52 (mapcar (lambda (profile-dir)
53 (concat profile-dir "/share/emacs/native-lisp/"))
54 (nix--profile-paths))
55 (cdr native-comp-eln-load-path))))
57 ;;; Make `woman' find the man pages
58 (defvar woman-manpath)
59 (eval-after-load 'woman
60 '(setq woman-manpath
61 (append (mapcar (lambda (x) (concat x "/share/man/"))
62 (nix--profile-paths))
63 woman-manpath)))
65 ;;; Make tramp work for remote NixOS machines
66 (defvar tramp-remote-path)
67 (eval-after-load 'tramp
68 ;; TODO: We should also add the other `NIX_PROFILES' to this path.
69 ;; However, these are user-specific, so we would need to discover
70 ;; them dynamically after connecting via `tramp'
71 '(progn
72 (add-to-list 'tramp-remote-path "/run/current-system/sw/bin")
73 (add-to-list 'tramp-remote-path "/run/wrappers/bin")))
75 ;;; C source directory
76 ;;;
77 ;;; Computes the location of the C source directory from the path of
78 ;;; the current file:
79 ;;; from: /nix/store/<hash>-emacs-<version>/share/emacs/site-lisp/site-start.el
80 ;;; to: /nix/store/<hash>-emacs-<version>/share/emacs/<version>/src/
81 (defvar find-function-C-source-directory)
82 (let ((emacs
83 (file-name-directory ; .../emacs/
84 (directory-file-name ; .../emacs/site-lisp
85 (file-name-directory load-file-name)))) ; .../emacs/site-lisp/
86 (version
87 (file-name-as-directory
88 emacs-version))
89 (src (file-name-as-directory "src")))
90 (setq find-function-C-source-directory (concat emacs version src)))