From 1543c8cc01a4501ec9286e03ccf92965deff611e Mon Sep 17 00:00:00 2001 From: Moritz Ulrich Date: Thu, 4 Jan 2018 11:16:35 +0100 Subject: [PATCH 1/2] emacs: Add more documentation to `site-start.el` `site-start.el` is the file loaded on startup, containing nix-specific customizations like adding paths in `NIX_PROFILES` to the emacs-specific search-path (`load-path`) or making man-pages in these directories discoverable. --- pkgs/applications/editors/emacs/site-start.el | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/editors/emacs/site-start.el b/pkgs/applications/editors/emacs/site-start.el index b41ca92db08..004b917ebb6 100644 --- a/pkgs/applications/editors/emacs/site-start.el +++ b/pkgs/applications/editors/emacs/site-start.el @@ -1,18 +1,28 @@ -;;; NixOS specific load-path +(defun nix--profile-paths () + "Returns a list of all paths in the NIX_PROFILES environment +variable, ordered from more-specific (the user profile) to the +least specific (the system profile)" + (reverse (split-string (or (getenv "NIX_PROFILES") "")))) + +;;; Extend `load-path' to search for elisp files in subdirectories of +;;; all folders in `NIX_PROFILES' (setq load-path - (append (reverse (mapcar (lambda (x) (concat x "/share/emacs/site-lisp/")) - (split-string (or (getenv "NIX_PROFILES") "")))) + (append (mapcar (lambda (x) (concat x "/share/emacs/site-lisp/")) + (nix--profile-paths)) load-path)) ;;; Make `woman' find the man pages (eval-after-load 'woman '(setq woman-manpath - (append (reverse (mapcar (lambda (x) (concat x "/share/man/")) - (split-string (or (getenv "NIX_PROFILES") "")))) + (append (mapcar (lambda (x) (concat x "/share/man/")) + (nix--profile-paths)) woman-manpath))) ;;; Make tramp work for remote NixOS machines (eval-after-load 'tramp + ;; 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' '(add-to-list 'tramp-remote-path "/run/current-system/sw/bin")) ;;; C source directory @@ -22,9 +32,9 @@ ;;; from: /nix/store/-emacs-/share/emacs/site-lisp/site-start.el ;;; to: /nix/store/-emacs-/share/emacs//src/ (let ((emacs - (file-name-directory ;; .../emacs/ - (directory-file-name ;; .../emacs/site-lisp - (file-name-directory load-file-name)))) ;; .../emacs/site-lisp/ + (file-name-directory ; .../emacs/ + (directory-file-name ; .../emacs/site-lisp + (file-name-directory load-file-name)))) ; .../emacs/site-lisp/ (version (file-name-as-directory (concat From 7cfdb2b1b56f25c166feee2780d7b1b59eea8923 Mon Sep 17 00:00:00 2001 From: Moritz Ulrich Date: Thu, 4 Jan 2018 11:48:25 +0100 Subject: [PATCH 2/2] emacs: Search subdirectories of `site-lisp` in `NIX_PROFILES` This adds subdirectories of `share/emacs/site-lisp/` in every path in `NIX_PROFILES` to `load-path` to allow loading of more complex libraries like `mu4e`. Fixes #33412 --- pkgs/applications/editors/emacs/site-start.el | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/editors/emacs/site-start.el b/pkgs/applications/editors/emacs/site-start.el index 004b917ebb6..cc1ab1d0e30 100644 --- a/pkgs/applications/editors/emacs/site-start.el +++ b/pkgs/applications/editors/emacs/site-start.el @@ -5,11 +5,22 @@ least specific (the system profile)" (reverse (split-string (or (getenv "NIX_PROFILES") "")))) ;;; Extend `load-path' to search for elisp files in subdirectories of -;;; all folders in `NIX_PROFILES' -(setq load-path - (append (mapcar (lambda (x) (concat x "/share/emacs/site-lisp/")) - (nix--profile-paths)) - load-path)) +;;; all folders in `NIX_PROFILES'. Also search for one level of +;;; subdirectories in these directories to handle multi-file libraries +;;; like `mu4e'.' +(require 'seq) +(let* ((subdirectory-sites (lambda (site-lisp) + (when (file-exists-p site-lisp) + (seq-filter (lambda (f) (file-directory-p (file-truename f))) + ;; Returns all files in `site-lisp', excluding `.' and `..' + (directory-files site-lisp 'full "^\\([^.]\\|\\.[^.]\\|\\.\\..\\)"))))) + (paths (apply #'append + (mapcar (lambda (profile-dir) + (let ((site-lisp (concat profile-dir "/share/emacs/site-lisp/"))) + (cons site-lisp (funcall subdirectory-sites site-lisp)))) + (nix--profile-paths))))) + (setq load-path (append paths load-path))) + ;;; Make `woman' find the man pages (eval-after-load 'woman