From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id AOXEFGsxU2PhgwAAbAwnHQ (envelope-from ) for ; Sat, 22 Oct 2022 01:55:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id wKv4E2sxU2MurQAAG6o9tA (envelope-from ) for ; Sat, 22 Oct 2022 01:55:23 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EA86D3B394 for ; Sat, 22 Oct 2022 01:55:22 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1om0CB-00045a-EU; Fri, 21 Oct 2022 18:08:51 -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 ) id 1olxec-00029T-D0 for guix-patches@gnu.org; Fri, 21 Oct 2022 15:26:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olxec-0004tK-69 for guix-patches@gnu.org; Fri, 21 Oct 2022 15:26:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1olxeb-00048z-Vn for guix-patches@gnu.org; Fri, 21 Oct 2022 15:26:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58693] [PATCH 1/1] gnu: home: Add home-emacs-service-type. References: <20221021192328.4833-1-paren@disroot.org> In-Reply-To: <20221021192328.4833-1-paren@disroot.org> Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 21 Oct 2022 19:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58693 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58693@debbugs.gnu.org Cc: "\(" Received: via spool by 58693-submit@debbugs.gnu.org id=B58693.166638030615792 (code B ref 58693); Fri, 21 Oct 2022 19:26:01 +0000 Received: (at 58693) by debbugs.gnu.org; 21 Oct 2022 19:25:06 +0000 Received: from localhost ([127.0.0.1]:39060 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1olxdh-00046d-Pm for submit@debbugs.gnu.org; Fri, 21 Oct 2022 15:25:06 -0400 Received: from knopi.disroot.org ([178.21.23.139]:58678) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1olxdf-00046V-Nu for 58693@debbugs.gnu.org; Fri, 21 Oct 2022 15:25:04 -0400 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 2B8DA4E85E; Fri, 21 Oct 2022 21:25:03 +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 l-kvisXl1BMA; Fri, 21 Oct 2022 21:25:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1666380301; bh=u3sHr/NDhZF7M4jXBAH1QFadc7uus1T0aOMwbVsHgE4=; h=From:To:Cc:Subject:Date; b=FiddV2esqo7ccVfZL6MgSCthP3UZgNPvy1goXwD9ePMOvWBPZ6fUJnhKN/LMrPXLu s2BznQwV6WRQVJOE9MRJQMcwi/l1mxSmwKRVRhQcpGkb+YxH/tQxcSNwFNN+B4vzIz nurPYC0ujcpHHV6xWipcWeJ3+WDs74PzKH72Rwel2hvQV7Dv777rIas8De7EgKsXXW lUx2YCbstM7iH5l0TWzudj4BUDDiO6GgaV75UbNY8lpmZ2AmAW0/ljPPVEvYg+0RJ4 J89HQLswkWwdjm5gKCClr1O3mqiPsyfRWkD7xsGo38EEuGeUFSyvIie6J4Z2mXf+nM 815/JvNDnfJgQ== Date: Fri, 21 Oct 2022 20:24:58 +0100 Message-Id: <20221021192458.4956-1-paren@disroot.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Guix-patches" Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" From: "\( via Guix-patches" via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666396523; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Ru/QcTGTIMN9uuPnMH1SZD21c6Fhh2HA7r3BgCgVx6c=; b=S2czbEW7y5CuBe4YdJ2X5TQwZGJrpjNm4/Am2cunX6o05lc4EtcNHTjntbVLsJJJIs/764 NnAkuR2ke1+cwVVK1y8huV/+SYyTOtZfX5PYG10aB2Ukzmq6qEo541vB5ITk3ToI3OoCMx P1+DfpBUpKmK9vYGtgiaLhbmYuwqPDIc36UbUYDdOBmJxa4BbwFNFTsK670W6XPYZXWkfn B75DNeD8poclTt8ElQELmE4tjfd74BSrI0FuU5ta8phfsdlpZLFrkBe2Sn7Bw/8Z4pOFGt 7dSF5FpuVTqS7EJv8bnIMFP24PpF8up0bDg8nPkQaEIC4dXFivtc3uJMeHBEwg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666396523; a=rsa-sha256; cv=none; b=qKIfgNgezJR1SxartUYV1nI98nqV092uDWNz6ERMQNaJh9VL9YTkHnLR2BgOKekZ8R9VZZ BzmZpkoIfgCwHGGHmpqyMNPfm+w9W6rJkRxMoFR4pJlCFuKKhOnAgsd4Qt4wjrxJzDVGtO xCF1a7yZMzV7ydm4Rz0e9cQw9/99YWBDczFHd/5qYTYao8WZ/Rsd9PUBnSD26aACPqGweP sqkGQqmHTWESUN9yxgGe6pqCT2GIb0FjTyOsrpm9Py1QAbGHoPXJg4G5YjOmUhXUa6L4oT yO3bLrTlcYuiBeasO/pqpxMsmf4vqAbGCXMpxMwO4NWOI5UtqrAi3MoIWLpsTQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=FiddV2es; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.44 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=FiddV2es; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: EA86D3B394 X-Spam-Score: -1.44 X-Migadu-Scanner: scn1.migadu.com X-TUID: 9vmxcofzHt4P * gnu/local.mk (GNU_SYSTEM_MODULES): Add gnu/home/services/emacs.scm. * gnu/home/services/emacs.scm (home-emacs-configuration): New record type. (home-emacs-service-type): New variable. * doc/guix.texi: Document them. --- doc/guix.texi | 51 ++++++++++++ gnu/home/services/emacs.scm | 162 ++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 3 files changed, 214 insertions(+) create mode 100644 gnu/home/services/emacs.scm diff --git a/doc/guix.texi b/doc/guix.texi index 3bf2dee752..dc27b7437e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -40517,6 +40517,7 @@ services)}. * Shepherd: Shepherd Home Service. Managing User's Daemons. * SSH: Secure Shell. Setting up the secure shell client. * Desktop: Desktop Home Services. Services for graphical environments. +* Emacs: Emacs Home Service. Service for running Emacs. * Guix: Guix Home Services. Services for Guix. @end menu @c In addition to that Home Services can provide @@ -41348,6 +41349,56 @@ The package providing the @code{/bin/dbus-daemon} command. @end table @end deftp +@node Emacs Home Service +@subsection Emacs Home Service + +@defvr {Scheme Variable} home-emacs-service-type +This is the service type for configuring the Emacs text editor and +running its daemon. + +Note that if you have an existing @file{~/.emacs} and/or +@file{~/.emacs.d}, the configuration aspect of this service will +not function, as they take precedence over @file{~/.config/emacs}, +which this service uses in the interest of cleanliness. To migrate +to the XDG directory, run these commands: + +@example +$ cp ~/.emacs.d $XDG_CONFIG_HOME/emacs +$ cp ~/.emacs $XDG_CONFIG_HOME/emacs/init.el +@end example +@end defvr + +@deftp {Data Type} home-emacs-configuration +The configuration record for @code{home-emacs-service-type}. + +@table @asis +@item @code{emacs} (default: @code{emacs}) +The package providing the @file{/bin/emacs} and @file{/bin/emacsclient} +commands. + +@item @code{packages} (default: @code{'()}) +Packages providing Emacs plugins to add to the daemon's load paths. + +@item @code{native-compile?} (default: @code{#f}) +Whether to recompile all @code{packages}, using the provided @code{emacs} +package in place of @code{emacs-minimal}, which will enable native +compilation if the @code{emacs} package supports it. All +non-@code{-minimal} Emacs packages at version 28 or above should support +native compilation. + +@item @code{init-file} (default: @code{(plain-file "init.el" "")}) +The file-like to use as @file{init.el}, the main Emacs configuration +file. + +@item @code{early-init-file} (default: @code{(plain-file "early-init.el" "")}) +The file-like to use as @file{early-init.el}, which is loaded early in +the initialisation process, before the GUI is started. + +@item @code{debug?} (default: @code{#f}) +Whether to enable detailed debug log output with backtraces. +@end table +@end deftp + @node Guix Home Services @subsection Guix Home Services diff --git a/gnu/home/services/emacs.scm b/gnu/home/services/emacs.scm new file mode 100644 index 0000000000..a727a2f246 --- /dev/null +++ b/gnu/home/services/emacs.scm @@ -0,0 +1,162 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 ( +;;; +;;; 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 . + +(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."))) diff --git a/gnu/local.mk b/gnu/local.mk index 8247180bef..3431c771b8 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -88,6 +88,7 @@ GNU_SYSTEM_MODULES = \ %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/pm.scm \ -- 2.38.0