From ac3c3773f3b8c2ef33f75a9305159d7337179402 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Wed, 3 Sep 2025 20:56:37 +0200 Subject: [PATCH] feat: emacs sets PATH to prepend emacs it's starting to PATH --- modules/ruther/home/services/wayland.scm | 71 +++++++++++++++++++++--- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/modules/ruther/home/services/wayland.scm b/modules/ruther/home/services/wayland.scm index 1320807f0df81f8022cf3742ffd2affb0b9db2ce..c589be6c1e7dfe246a86fc7db7c6389cea8f07ca 100644 --- a/modules/ruther/home/services/wayland.scm +++ b/modules/ruther/home/services/wayland.scm @@ -3,6 +3,7 @@ #:use-module (gnu packages wm) #:use-module (gnu packages emacs) #:use-module (gnu packages gnome) + #:use-module (gnu packages bash) #:use-module (gnu packages networking) #:use-module (gnu packages xdisorg) #:use-module (gnu services) @@ -53,7 +54,7 @@ (remove (cut string-prefix? "DISPLAY=" <>) (default-environment-variables)))))) -(define %xwayland-display-environ +(define* (make-xwayland-display-environ #:key (extra-environment-variables #~(default-environment-variables))) #~(begin (use-modules (shepherd service) (shepherd support)) @@ -69,7 +70,10 @@ (string-append "WAYLAND_DISPLAY=" wayland-display) (remove (lambda (var) (or (string-prefix? "DISPLAY=" var) (string-prefix? "WAYLAND_DISPLAY=" var))) - (default-environment-variables)))))) + #$extra-environment-variables))))) + +(define %xwayland-display-environ + (make-xwayland-display-environ)) (define (x-display-shepherd-service config) (list @@ -191,14 +195,63 @@ This should be called from a wayland compositor like this: `herd start wayland-d (requirement '(wayland-display dbus)) (provision '(emacs)) (auto-start? #f) - (modules %display-environ-modules) + (modules (cons* + '(ice-9 popen) + '(ice-9 rdelim) + %display-environ-modules)) (start #~(lambda _ - (fork+exec-command - (cons* - #$(file-append (home-emacs-configuration-emacs config) "/bin/emacs") - "--fg-daemon" - '#$(home-emacs-configuration-extra-arguments config)) - #:environment-variables #$%xwayland-display-environ))) + ;; TODO hey.. DON'T SET the environment of the + ;; shepherd you idiot. Just save it in a variable. + ;; Well I will do that later. + ;; (environ (default-environment-variables)) + ;; (environ `(,(string-append "HOME=" (getenv "HOME")) + ;; ,(string-append "USER=" (getenv "USER")) + ;; ,(string-append "XDG_RUNTIME_DIR=" (getenv "XDG_RUNTIME_DIR")) + ;; ,(string-append "SHELL=" (getenv "SHELL")))) + + ;; ;; Obtain environment from login shell! + ;; (let ((port (open-input-pipe + ;; (string-append #$(file-append bash "/bin/bash") + ;; " --login -c env"))) + ;; (capture-variables '("PATH" "MANPATH" "INFOPATH" "CXX" "CC" "XDG_CONFIG_HOME" "XDG_CACHE_HOME" "NIX_PATH" "GUILE_LOAD_PATH" "GUILE_LOAD_COMPILED_PATH" + ;; "XDG_CACHE_HOME" "XDG_DATA_HOME" "XDG_CONFIG_DIRS" "XDG_DATA_DIRS" "XDG_STATE_HOME" + ;; "TREE_SITTER_GRAMMAR_PATH" "SSL_CERT_DIR" "SSL_CERT_FILE" "GIT_SSL_CAINFO"))) + ;; (let loop ((line (read-line port))) + ;; (unless (eof-object? line) + ;; (let ((splitted (string-split line #\=))) + ;; (when (member (car splitted) capture-variables) + ;; (setenv (car splitted) (cadr splitted))) + ;; (loop (read-line port)))))) + + ;; ;; Prepend emacs's /bin to PATH + ;; (setenv "PATH" + ;; (string-append + ;; #$(file-append (home-emacs-configuration-emacs config) "/bin") + ;; ":" + ;; (or (getenv "PATH") ""))) + + + (let* ((base-env-vars #$%xwayland-display-environ) + (env-vars + (cons* + ;; My own variable to not load login shell + "EMACS_NO_SHELL_ENV=1" + (map + (lambda (var) + (if (string-prefix? "PATH=" var) + (string-append + "PATH=" + #$(file-append (home-emacs-configuration-emacs config) "/bin") + ":" + (substring var 5)) + var)) + base-env-vars)))) + (fork+exec-command + (cons* + #$(file-append (home-emacs-configuration-emacs config) "/bin/emacs") + "--fg-daemon" + '#$(home-emacs-configuration-extra-arguments config)) + #:environment-variables env-vars)))) (stop #~(make-kill-destructor))))) (define-public home-emacs-service-type