all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 55d373f2176381d99917bedb4010aff3c4f1e7f3 8513 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022, 2023 ( <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 emacs-minimal)
  #:use-module (gnu services configuration)
  #:use-module (guix derivations)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix profiles)
  #:use-module (guix records)
  #:use-module (guix search-paths)
  #:use-module (guix store)
  #:use-module (ice-9 match)
  #:export (home-emacs-configuration
            home-emacs-service-type))

(define list-of-string?
  (list-of string?))

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

(define file-like-or-#f?
  (match-lambda
    ((or #f (? file-like?)) #t)
    (_ #f)))

(define-configuration/no-serialization home-emacs-configuration
  (servers
   (list-of-string (list "server"))
   "List of strings which name Emacs servers to run.")
  (emacs
   (file-like emacs)
   "The package providing @file{/bin/emacs}.")
  (packages
   (list-of-file-likes '())
   "Packages to add to the Emacs load path.")
  (native-compile?
   (boolean #f)
   "Whether to enable native-compilation of Emacs packages by building them with
@code{emacs} rather than @code{emacs-minimal}.  Has no effect if
@code{compilation-emacs} is not set to @code{#f}.")
  (compilation-emacs
   (file-like-or-#f #f)
   "The Emacs to use to compile Emacs packages.  If @code{#f}, default to
@code{emacs-minimal}.")
  (init-file
   (file-like (plain-file "init.el" ""))
   "File-like object to use as the Emacs initialisation script.")
  (early-init-file
   (file-like (plain-file "early-init.el" ""))
   "File-like object to use as the Emacs early-initialisation script.")
  (debug?
   (boolean #f)
   "Whether to enable debug output from Emacs."))

(define (emacs-for-compile config)
  "Using CONFIG, figure out and return the Emacs package to use in the compilation of
Emacs plugins."
  (match-record config <home-emacs-configuration> (native-compile?
                                                   compilation-emacs)
    (cond
     (compilation-emacs compilation-emacs)
     (native-compile? emacs)
     (else emacs-minimal))))

(define (transformed-emacs-packages config)
  "Return the PACKAGES of CONFIG, transformed to use the result of EMACS-FOR-COMPILE
rather than EMACS-MINIMAL for compilation."
  (match-record config <home-emacs-configuration> (packages)
    (map (package-input-rewriting
          `((,emacs-minimal . ,(emacs-for-compile config))))
         packages)))

(define (make-emacs-profile config)
  "Return a declarative profile value called ``emacs-profile'' corresponding to
CONFIG."
  (match-record config <home-emacs-configuration> (packages)
    (profile
     (name "emacs-profile")
     (content (packages->manifest (cons (emacs-for-compile config)
                                        packages))))))

;; XXX: It would be preferable to just ungexp the profile object within the
;; EMACS-ENVIRONMENT gexp, and do the PROFILE-SEARCH-PATH dance within it, but
;; both MATCH-RECORD and record field accessors don't seem to work in gexps.
(define (build-emacs-profile config)
  "Return the path to a newly-built store item containing a profile corresponding to
CONFIG."
  (with-store store
    (run-with-store store
      (mlet %store-monad
          ((profile-drv (lower-object
                         (make-emacs-profile config))))
        (mbegin %store-monad
          (built-derivations (list profile-drv))
          (return (derivation-output-path
                   (assoc-ref (derivation-outputs profile-drv)
                              "out"))))))))

(define (emacs-environment config)
  "Return a list of ``VARIABLE=VALUE'' strings corresponding to variables to be set
in the Emacs daemon's environment."
  #~(map (lambda (env-var)
           ;; XXX: Not only does it seem that MATCH-RECORD blows up in gexps, but
           ;; MATCH-LAMBDA too...  Stick with this, admittedly ugly, solution for
           ;; now.
           (let ((variable (list-ref env-var 0))
                 (separator (list-ref env-var 1))
                 (value (list-ref env-var 2)))
             (string-append variable "="
                            (or (and=> (getenv variable)
                                       (lambda (original)
                                         (string-append original
                                                        separator)))
                                "")
                            value)))
         '(#$@(map (match-lambda
                     ((spec . value)
                      (match-record spec <search-path-specification>
                          (variable separator)
                        (list variable separator value))))
                   (profile-search-paths
                    (build-emacs-profile config))))))

(define (home-emacs-profile-packages config)
  (match-record config <home-emacs-configuration> (emacs)
    (list emacs)))

(define (home-emacs-shepherd-services config)
  (match-record config <home-emacs-configuration> (servers emacs debug?)
    (map (lambda (server)
           (shepherd-service
            (provision (list (string->symbol
                              (string-append "emacs-" server))))
            (documentation
             (string-append "Start the Emacs server called "
                            server "."))
            (start
             #~(make-forkexec-constructor
                (list #$(file-append emacs "/bin/emacs")
                      (string-append "--fg-daemon=" #$server)
                      "--eval"
                      (format #f "~s"
                              `(progn
                                (setq custom-file
                                      ,(format #f "~a/emacs/custom.el"
                                               (or (getenv "XDG_CONFIG_HOME")
                                                   (format #f "~a/.config"
                                                           (getenv "HOME")))))
                                (load custom-file)))
                      #$@(if debug?
                             (list "--debug-init")
                             '()))
                #:log-file
                (format #f "~a/log/emacs/~a.log"
                        (or (getenv "XDG_STATE_HOME")
                            (format #f "~a/.local/state"
                                    (getenv "HOME")))
                        #$server)
                #:environment-variables
                (append (default-environment-variables)
                        #$(emacs-environment config))))
            (stop
             #~(make-forkexec-constructor
                (list #$(file-append emacs "/bin/emacsclient")
                      "-s" #$server "--eval" "(kill-emacs)")))))
         servers)))

(define (home-emacs-xdg-configuration-files config)
  (match-record config <home-emacs-configuration> (early-init-file
                                                   init-file)
    `(("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 55d373f217 ...
found 55d373f217 in https://yhetil.org/guix/20230330190050.18037-1-paren@disroot.org/

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

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

index at:
100644 55d373f2176381d99917bedb4010aff3c4f1e7f3	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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.