···11-;;; NixOS specific load-path
22-(setq load-path
33- (append (reverse (mapcar (lambda (x) (concat x "/share/emacs/site-lisp/"))
44- (split-string (or (getenv "NIX_PROFILES") ""))))
55- load-path))
11+(defun nix--profile-paths ()
22+ "Returns a list of all paths in the NIX_PROFILES environment
33+variable, ordered from more-specific (the user profile) to the
44+least specific (the system profile)"
55+ (reverse (split-string (or (getenv "NIX_PROFILES") ""))))
66+77+;;; Extend `load-path' to search for elisp files in subdirectories of
88+;;; all folders in `NIX_PROFILES'. Also search for one level of
99+;;; subdirectories in these directories to handle multi-file libraries
1010+;;; like `mu4e'.'
1111+(require 'seq)
1212+(let* ((subdirectory-sites (lambda (site-lisp)
1313+ (when (file-exists-p site-lisp)
1414+ (seq-filter (lambda (f) (file-directory-p (file-truename f)))
1515+ ;; Returns all files in `site-lisp', excluding `.' and `..'
1616+ (directory-files site-lisp 'full "^\\([^.]\\|\\.[^.]\\|\\.\\..\\)")))))
1717+ (paths (apply #'append
1818+ (mapcar (lambda (profile-dir)
1919+ (let ((site-lisp (concat profile-dir "/share/emacs/site-lisp/")))
2020+ (cons site-lisp (funcall subdirectory-sites site-lisp))))
2121+ (nix--profile-paths)))))
2222+ (setq load-path (append paths load-path)))
2323+624725;;; Make `woman' find the man pages
826(eval-after-load 'woman
927 '(setq woman-manpath
1010- (append (reverse (mapcar (lambda (x) (concat x "/share/man/"))
1111- (split-string (or (getenv "NIX_PROFILES") ""))))
2828+ (append (mapcar (lambda (x) (concat x "/share/man/"))
2929+ (nix--profile-paths))
1230 woman-manpath)))
13311432;;; Make tramp work for remote NixOS machines
1533(eval-after-load 'tramp
3434+ ;; TODO: We should also add the other `NIX_PROFILES' to this path.
3535+ ;; However, these are user-specific, so we would need to discover
3636+ ;; them dynamically after connecting via `tramp'
1637 '(add-to-list 'tramp-remote-path "/run/current-system/sw/bin"))
17381839;;; C source directory
···2243;;; from: /nix/store/<hash>-emacs-<version>/share/emacs/site-lisp/site-start.el
2344;;; to: /nix/store/<hash>-emacs-<version>/share/emacs/<version>/src/
2445(let ((emacs
2525- (file-name-directory ;; .../emacs/
2626- (directory-file-name ;; .../emacs/site-lisp
2727- (file-name-directory load-file-name)))) ;; .../emacs/site-lisp/
4646+ (file-name-directory ; .../emacs/
4747+ (directory-file-name ; .../emacs/site-lisp
4848+ (file-name-directory load-file-name)))) ; .../emacs/site-lisp/
2849 (version
2950 (file-name-as-directory
3051 (concat