Received: (at submit) by debbugs.gnu.org; 30 Mar 2023 19:01:11 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 30 15:01:10 2023 Received: from localhost ([127.0.0.1]:59445 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1phxWH-0008Ad-R6 for submit <at> debbugs.gnu.org; Thu, 30 Mar 2023 15:01:10 -0400 Received: from lists.gnu.org ([209.51.188.17]:45762) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <paren@HIDDEN>) id 1phxWF-0008AU-0z for submit <at> debbugs.gnu.org; Thu, 30 Mar 2023 15:01:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <paren@HIDDEN>) id 1phxWE-0001io-RH for guix-patches@HIDDEN; Thu, 30 Mar 2023 15:01:06 -0400 Received: from knopi.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <paren@HIDDEN>) id 1phxWB-0003ZM-Te for guix-patches@HIDDEN; Thu, 30 Mar 2023 15:01:06 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 0A6ED40200; Thu, 30 Mar 2023 21:01:00 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DH5fDTSNJwN4; Thu, 30 Mar 2023 21:00:57 +0200 (CEST) From: "(" <paren@HIDDEN> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1680202857; bh=kX2K9qUUNI/h2oZ9iD1VHr51v8+07b3+dcdhYDYXQZ8=; h=From:To:Cc:Subject:Date; b=XX/jqM7NJnbHTYKHmypfcoTh0HDZvFK2iaZ8bfAPgSTy+doV3k+gMHUR3BZpUu0Nw G0+IEH1PY66HLgtt0vBdnJzd4n8Id8a7OHwaYf+n6+T/0hrku0K+VeDZrGfWWgIrPv I8fYv3SqPuiGp9L6wvYRmE0CdZPDiLyNPMXO+wR6Cuig36D+I9tVsAGWfn4mt4kf9o 5uQQbBiVnKNE9pr1cFeJRkq0QZTescpaCDJ8kekqrceIUid3GutpMcQiWR+PIro8Qy VUI4TJc3rCTLvib2GL43vAchY5Qk4puPNBygR2/NEkLxNP/DXTt+N7tBFhffCXp7d0 Nbc/w4UHzW+mw== To: guix-patches@HIDDEN Subject: [PATCH] gnu: home: Add home-emacs-service-type. Date: Thu, 30 Mar 2023 20:00:50 +0100 Message-Id: <20230330190050.18037-1-paren@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=178.21.23.139; envelope-from=paren@HIDDEN; helo=knopi.disroot.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: "\(" <paren@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -2.4 (--) * gnu/home/services/emacs.scm (home-emacs-service-type): New variable. (home-emacs-configuration): New record type. * doc/guix.texi: Document them. * gnu/local.mk: Add gnu/home/services/emacs.scm. Reorder gnu/home/services entries alphabetically. --- Heya Guix, A while ago, I attempted to add a HOME-EMACS-SERVICE-TYPE to Guix[1]; a few suggestions for improvement were made, but I was not at the time knowledgeable enough to implement them; yesterday, however, I rewrote[2] the version of the service included in the Guix 'R' Us, adding a few features and greatly improving the design of the service. The service now supports defining the Emacs used for package compilation separately from the Emacs run by the service, and allows you to run multiple differently-named daemons at once. Its internals have been reworked to build a profile for the Emacs packages, rather than the poorly-conceived, ugly system that previously existed (where the packages were scanned for Emacs module directories). [1] https://issues.guix.gnu.org/58693 [2] https://git.sr.ht/~whereiseveryone/guixrus/commit/4037eb43428f4beb335e30c234c71949529d8ef0 https://git.sr.ht/~whereiseveryone/guixrus/commit/5104909976c7f67881233d2ff2bf52249a3aa162 https://git.sr.ht/~whereiseveryone/guixrus/commit/0b20fef8d54ac60bf31f2dc473f04bd46dea5792 doc/guix.texi | 95 +++++++++++++++- gnu/home/services/emacs.scm | 211 ++++++++++++++++++++++++++++++++++++ gnu/local.mk | 7 +- 3 files changed, 309 insertions(+), 4 deletions(-) create mode 100644 gnu/home/services/emacs.scm diff --git a/doc/guix.texi b/doc/guix.texi index c49e51b72e..f296743b16 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -107,7 +107,7 @@ Copyright @copyright{} 2022 Karl Hallsby@* Copyright @copyright{} 2022 Justin Veilleux@* Copyright @copyright{} 2022 Reily Siegel@* Copyright @copyright{} 2022 Simon Streit@* -Copyright @copyright{} 2022 (@* +Copyright @copyright{} 2022-2023 (@* Copyright @copyright{} 2022 John Kehayias@* Copyright @copyright{} 2022–2023 Bruno Victal@* Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@* @@ -41793,6 +41793,7 @@ services)}. * Sound: Sound Home Services. Dealing with audio. * Messaging: Messaging Home Services. Services for managing messaging. * Media: Media Home Services. Services for managing media. +* Emacs: Emacs Home Services. Manage the Emacs daemon. @end menu @c In addition to that Home Services can provide @@ -42981,6 +42982,98 @@ kodi} for more information. @end table @end deftp +@node Emacs Home Services +@subsection Emacs Home Services + +@cindex emacs +The @uref{https://gnu.org/s/emacs, GNU Emacs} extensible text editor can +be run as a daemon, allowing you to connect multiple Emacs windows to a +single core process using @command{emacsclient}. The +@code{home-emacs-service-type}, exported from +@code{(gnu home services emacs)}, allows you to launch this daemon on +login using Guix Home. + +Here is a very basic example of an Emacs service configuration, +including a single package and enabling native compilation support: + +@lisp +(service home-emacs-service-type + (home-emacs-configuration + (packages (list emacs-magit)) + (native-compile? #t))) +@end lisp + +The service supports running multiple differently-named Emacs daemons +simultaneously, which can be connected to using the @code{-s NAME} flag +of @command{emacsclient}; here is a more complex service configuration +utilising this feature: + +@lisp +(service home-emacs-service-type + (home-emacs-configuration + (servers (list "server" + "mail")) + (emacs emacs-next-pgtk) + (packages (list emacs-magit)) + (native-compile? #t) + (debug? #t))) +@end lisp + +As well as adding a @code{"mail"} server, this configuration changes the +version of Emacs to the latest experimental version available in Guix, +with the pure-GTK UI enabled, and enables debug log output. Make sure +you include @code{"server"} in the @code{servers} list, as it provides +the default server. + +@defvar home-emacs-service-type +Type of the service available from @code{(gnu home services emacs)}, +taking as its configuration value a @code{home-emacs-configuration} +object. + +Logs for this service may be found at +@file{@var{XDG_STATE_HOME}/log/emacs/SERVER-NAME.log}; the value of +@var{XDG_STATE_HOME} is often either @file{~/.local/state} or +@file{~/.local/var/lib}. +@end defvar + +@deftp {Data Type} home-emacs-configuration +Record for configuring @code{home-emacs-service-type}. Available fields +are: + +@table @asis +@item @code{services} (default: @code{(list "server")}) (type: string) +List of strings naming Emacs servers to run. To write ELisp conditional +on the name of the server it is run under, use the @code{server-name} +variable. + +@item @code{emacs} (default: @code{emacs}) (type: file-like) +Package providing @file{/bin/emacs}. + +@item @code{packages} (default: @code{'()}) (type: list-of-file-likes) +Packages to give Emacs access to. + +@item @code{native-compile?} (default: @code{#f}) (type: boolean) +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 specified. + +@item @code{compilation-emacs} (default: @code{#f}) (type: file-like-or-#f) +Emacs to use to compile Emacs packages. If @code{#f}, default to +@code{emacs} if @code{native-compile?} is @code{#t}, or +@code{emacs-minimal} otherwise. + +@item @code{init-file} (default: @code{(plain-file "init.el" "")} (type: file-like) +File-like to use as the Emacs initialisation script. + +@item @code{early-init-file} (default: @code{(plain-file "early-init.el" "")} (type: file-like) +File-like to use as the Emacs early-initialisation script, run before +the UI is set up. + +@item @code{debug?} (default: @code{#f}) (type: boolean) +Whether Emacs will print debug output to the log file. +@end table +@end deftp + @node Invoking guix home @section Invoking @command{guix home} diff --git a/gnu/home/services/emacs.scm b/gnu/home/services/emacs.scm new file mode 100644 index 0000000000..55d373f217 --- /dev/null +++ b/gnu/home/services/emacs.scm @@ -0,0 +1,211 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022, 2023 ( <paren@HIDDEN> +;;; +;;; 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."))) diff --git a/gnu/local.mk b/gnu/local.mk index aee0b8a645..fcdc651e7b 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -54,7 +54,7 @@ # Copyright © 2022 muradm <mail@HIDDEN> # Copyright © 2022 Hilton Chain <hako@HIDDEN> # Copyright © 2022 Alex Griffin <a@HIDDEN> -# Copyright © 2022 ( <paren@HIDDEN> +# Copyright © 2022, 2023 ( <paren@HIDDEN> # Copyright © 2022 jgart <jgart@HIDDEN> # Copyright © 2023 Zheng Junjie <873216071@HIDDEN> # @@ -89,9 +89,10 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/desktop.scm \ - %D%/home/services/symlink-manager.scm \ + %D%/home/services/emacs.scm \ %D%/home/services/fontutils.scm \ %D%/home/services/guix.scm \ + %D%/home/services/mcron.scm \ %D%/home/services/media.scm \ %D%/home/services/messaging.scm \ %D%/home/services/pm.scm \ @@ -99,7 +100,7 @@ GNU_SYSTEM_MODULES = \ %D%/home/services/shepherd.scm \ %D%/home/services/sound.scm \ %D%/home/services/ssh.scm \ - %D%/home/services/mcron.scm \ + %D%/home/services/symlink-manager.scm \ %D%/home/services/utils.scm \ %D%/home/services/xdg.scm \ %D%/image.scm \ base-commit: a6f98c64f65a2887a54236421d72eaa3aae95444 -- 2.39.2
"(" <paren@HIDDEN>
:guix-patches@HIDDEN
.
Full text available.guix-patches@HIDDEN
:bug#62549
; Package guix-patches
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.