unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob a727a2f246973bb2c7fbd0dbb52a48eb67f0b07b 6488 bytes (raw)
name: gnu/home/services/emacs.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 ( <paren@disroot.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu home services emacs)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:autoload   (gnu packages emacs) (emacs-minimal
                                     emacs)
  #:use-module (gnu services configuration)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix records)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)

  #:export (home-emacs-configuration
            home-emacs-service-type))

(define list-of-file-likes?
  (list-of file-like?))

(define-configuration/no-serialization home-emacs-configuration
  (emacs
   (file-like emacs)
   "The package providing @file{/bin/emacs}.")
  (packages
   (list-of-file-likes '())
   "Packages to add to the Emacs plugin load path.")
  (native-compile?
   (boolean #f)
   "Whether to compile the @code{packages} using the Emacs package
provided as the value of the @code{emacs} field, which will enable
native compilation if the @code{emacs} package supports it.")
  (init-file
   (file-like (plain-file "init.el" ""))
   "File-like to use as the initialisation Lisp file.")
  (early-init-file
   (file-like (plain-file "early-init.el" ""))
   "File-like to use as the pre-initialisation Lisp file.")
  (debug?
   (boolean #f)
   "Whether to enable debugging."))

(define (home-emacs-profile-packages config)
  (list (home-emacs-configuration-emacs config)))

(define (home-emacs-transformed-packages config)
  (map (if (home-emacs-configuration-native-compile? config)
           (package-input-rewriting
            `((,emacs-minimal
              . ,(home-emacs-configuration-emacs config))))
           identity)
       (let ((packages (home-emacs-configuration-packages config)))
         (concatenate
          (cons packages
                (map (compose (cute map second <>)
                              package-transitive-propagated-inputs)
                     packages))))))

(define (home-emacs-shepherd-services config)
  (list (shepherd-service
         (provision '(emacs))
         (documentation "Start the Emacs daemon.")
         (modules '((ice-9 ftw)
                    (srfi srfi-1)
                    (srfi srfi-26)))
         (start
          #~(make-forkexec-constructor
             (list #$(file-append
                      (home-emacs-configuration-emacs config)
                      "/bin/emacs")
                   "--fg-daemon" "--eval"
                   (format #f "~s"
                           `(progn
                             (setq custom-file
                                   (concat (or (getenv "XDG_CONFIG_HOME")
                                               (concat (getenv "HOME")
                                                       "/.config"))
                                           "/emacs/custom.el"))
                             (load custom-file)))
                   #$@(if (home-emacs-configuration-debug? config)
                          (list "--debug-init")
                          '()))
             #:log-file
             (format #f "~a/emacs.log"
                     (or (getenv "XDG_LOG_HOME")
                         (format #f "~a/.local/var/log"
                                 (getenv "HOME"))))
             #:environment-variables
             (let ((env-var
                    (lambda (name path)
                      (define (regular-directory? directory)
                        (not (member directory (list "." ".."))))

                      (define (package-paths package)
                        (let ((directory (string-append package "/" path)))
                          (if (file-exists? directory)
                              (cons directory
                                    (map (cute string-append directory "/" <>)
                                         (scandir directory regular-directory?)))
                              '())))

                      (let ((old-value (getenv name)))
                        (string-append
                         name "="
                         (string-join
                          (append-map
                           package-paths
                           (list #$@(home-emacs-transformed-packages config)))
                          ":" (if old-value
                                  'suffix
                                  'infix))
                         (or old-value ""))))))
               (append (default-environment-variables)
                       (list (env-var "EMACSLOADPATH"
                                      "share/emacs/site-lisp")
                             (env-var "EMACSNATIVELOADPATH"
                                      "lib/emacs/native-site-lisp"))))))
         (stop
          #~(make-forkexec-constructor
             (list #$(file-append
                      (home-emacs-configuration-emacs config)
                      "/bin/emacsclient")
                   "--eval" "(kill-emacs)"))))))

(define (home-emacs-xdg-configuration-files config)
  `(("emacs/early-init.el"
     ,(home-emacs-configuration-early-init-file config))
    ("emacs/init.el"
     ,(home-emacs-configuration-init-file config))))

(define home-emacs-service-type
  (service-type
   (name 'home-emacs)
   (extensions
    (list (service-extension
           home-profile-service-type
           home-emacs-profile-packages)
          (service-extension
           home-shepherd-service-type
           home-emacs-shepherd-services)
          (service-extension
           home-xdg-configuration-files-service-type
           home-emacs-xdg-configuration-files)))
   (default-value (home-emacs-configuration))
   (description
    "Configure and run the GNU Emacs extensible text editor.")))

debug log:

solving a727a2f246 ...
found a727a2f246 in https://yhetil.org/guix-patches/20221021192458.4956-1-paren@disroot.org/

applying [1/1] https://yhetil.org/guix-patches/20221021192458.4956-1-paren@disroot.org/
diff --git a/gnu/home/services/emacs.scm b/gnu/home/services/emacs.scm
new file mode 100644
index 0000000000..a727a2f246

Checking patch gnu/home/services/emacs.scm...
Applied patch gnu/home/services/emacs.scm cleanly.

index at:
100644 a727a2f246973bb2c7fbd0dbb52a48eb67f0b07b	gnu/home/services/emacs.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).