From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <guix-patches-bounces+larch=yhetil.org@gnu.org>
Received: from mp11.migadu.com ([2001:41d0:2:4a6f::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by ms5.migadu.com with LMTPS
	id QKsoLel0RmOYKgAAbAwnHQ
	(envelope-from <guix-patches-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Wed, 12 Oct 2022 10:03:53 +0200
Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by mp11.migadu.com with LMTPS
	id sLU/Lel0RmPQZAAA9RJhRA
	(envelope-from <guix-patches-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Wed, 12 Oct 2022 10:03:53 +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 72F083EC80
	for <larch@yhetil.org>; Wed, 12 Oct 2022 10:03:53 +0200 (CEST)
Received: from localhost ([::1]:51994 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <guix-patches-bounces+larch=yhetil.org@gnu.org>)
	id 1oiWiU-00024a-M3
	for larch@yhetil.org; Wed, 12 Oct 2022 04:03:50 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:57996)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1oiWgk-00023x-SF
 for guix-patches@gnu.org; Wed, 12 Oct 2022 04:02:03 -0400
Received: from debbugs.gnu.org ([209.51.188.43]:56503)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1oiWgk-0008GG-6h
 for guix-patches@gnu.org; Wed, 12 Oct 2022 04:02:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1oiWgj-0007QF-Vb
 for guix-patches@gnu.org; Wed, 12 Oct 2022 04:02:01 -0400
X-Loop: help-debbugs@gnu.org
Subject: [bug#58454] [PATCH] gnu: home: Add home-dbus-service-type.
References: <20221011194513.26008-1-paren@disroot.org>
In-Reply-To: <20221011194513.26008-1-paren@disroot.org>
Resent-From: "(" <paren@disroot.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: guix-patches@gnu.org
Resent-Date: Wed, 12 Oct 2022 08:02:01 +0000
Resent-Message-ID: <handler.58454.B58454.166556169528483@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 58454
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: patch
To: 58454@debbugs.gnu.org
Cc: "\(" <paren@disroot.org>
Received: via spool by 58454-submit@debbugs.gnu.org id=B58454.166556169528483
 (code B ref 58454); Wed, 12 Oct 2022 08:02:01 +0000
Received: (at 58454) by debbugs.gnu.org; 12 Oct 2022 08:01:35 +0000
Received: from localhost ([127.0.0.1]:55577 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1oiWgI-0007PL-Qi
 for submit@debbugs.gnu.org; Wed, 12 Oct 2022 04:01:35 -0400
Received: from knopi.disroot.org ([178.21.23.139]:57682)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <paren@disroot.org>) id 1oiWgG-0007PB-Dj
 for 58454@debbugs.gnu.org; Wed, 12 Oct 2022 04:01:33 -0400
Received: from localhost (localhost [127.0.0.1])
 by disroot.org (Postfix) with ESMTP id 04B004DAAE;
 Wed, 12 Oct 2022 10:01:31 +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 Ypv3HwIrSsfu; Wed, 12 Oct 2022 10:01:29 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail;
 t=1665561684; bh=5AxVktMPoiSqsLxJIZIK7ZwlRoE97olvik4dphPSuAE=;
 h=From:To:Cc:Subject:Date;
 b=B7aPTHGHtf8hvO2xo6/osHve+7Ltkopr2cIcLY7Vvzq4bMcVpCWplA1dpF+m+1Svn
 o//ah2KvtUfqYw6+j6y3s2oRxizM/7Fnw9AS+4WrIyOltgB8z5vMVTEPpFk9OEybpt
 4Q7ZZOYf120WUh6Ce1FOVKhArt6ZrgwFZn+XeErV8upFf3ekIwKgm4wrgaOnR4t+vK
 TscjC6W2YoqnE+q8kdlOVtvTyKVkCoYnRb3GrjOGHSYMdne+NT5qy1KrWaYTZYkfSC
 Vq9+PJXTN/thlK6cBIKoGYq/U/o7krON2YB/SYbpMv51MbukZ8y2HGGpk5qBy+/033
 RFfNQxj55eqDQ==
Date: Wed, 12 Oct 2022 09:01:16 +0100
Message-Id: <20221012080116.4935-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: <guix-patches.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/guix-patches>,
 <mailto:guix-patches-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/guix-patches>
List-Post: <mailto:guix-patches@gnu.org>
List-Help: <mailto:guix-patches-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/guix-patches>,
 <mailto:guix-patches-request@gnu.org?subject=subscribe>
Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org
Sender: "Guix-patches" <guix-patches-bounces+larch=yhetil.org@gnu.org>
Reply-to:  "\(" <paren@disroot.org>
X-ACL-Warn: ,  "\( via Guix-patches" <guix-patches@gnu.org>
From:  "\( via Guix-patches" via <guix-patches@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=1665561833;
	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=G9nGfB9aST1pNsMx1FVibok98GaMfdMsHXA0mt8JXDs=;
	b=tn3iMcTzAliQVew49fG2joxURDLmZZziC9+EcYmBWFKBqQb/twFu1DE0Ey75qC1NTC9DyY
	m2Ts5N4EpHgyNFKx0+COQGNunw4/iGKrd/ONKhflXTZYCwpnM2b3LvxKeT1Zx8ou4hmcec
	8g6YYeWkJDTn3tZFo6sxDlp3rjQaVQySRwOiJqywmid54mWE9M46sxqA/eqFX4l0HbMtkA
	faexI+CnvBxAY8j0Cb9dHvZymyU4JKeKqvjbpIlN5yPC6P8le4RHhum/UyDsPkib1YZDzC
	KY82p+AL62vuv3l8iHbVsf5O+ydi5hd5VQKrpvf74v27IvI/W7Uz0o+V7GDQww==
ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665561833; a=rsa-sha256; cv=none;
	b=WeH7tw8xnIRdVC/SKZYZuZpcuSmf17SsPcd8Be4DGdrizGw+OhBiHLrVM7zvQNNqEXzTFO
	yaCZzsO+H1T0TzaDEUuNhx5X78jPvdleJ0z13oY0QT9FniGKI/uAHUtMho6SDURhRm8hNT
	6gcsQunWnyaA2tqz2avTlqHgTgJgzR6d0HtK6LY8ZvC/ksZ42wFmftFNaTtaQDmskQM57C
	Jby3dM/dh3PJ1/bq4TW9PvNXtqeEgk2xZVtrKnJglARFQRS95IbibbW+/hz69Cr9RJVaRM
	JeObSItQ5DWgPZOMAjkwvcfe63n2hGTQktUhuRWpgVwTHfobaez0amCw9PUVwQ==
ARC-Authentication-Results: i=1;
	aspmx1.migadu.com;
	dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=B7aPTHGH;
	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: -2.90
Authentication-Results: aspmx1.migadu.com;
	dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=B7aPTHGH;
	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: 72F083EC80
X-Spam-Score: -2.90
X-Migadu-Scanner: scn1.migadu.com
X-TUID: IMgUnrtwzcYz

* gnu/home/services/desktop.scm (home-dbus-service-type): New
  variable.
(home-dbus-configuration): New record type.
* doc/guix.texi: Document them.
---
 doc/guix.texi                 | 17 ++++++++++
 gnu/home/services/desktop.scm | 58 ++++++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 5867acb746..990113703b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41262,6 +41262,23 @@ format.
 
 @end deftp
 
+@defvr {Scheme Variable} home-dbus-service-type
+This is the service type for running a session-specific D-Bus, for
+unprivileged applications that require D-Bus to be running.
+@end defvr
+
+@deftp {Data Type} home-dbus-configuration
+The configuration record for @code{home-dbus-service-type}.
+
+@table @asis
+@item @code{dbus} (default: @code{dbus})
+The package providing the @code{/bin/dbus-daemon} command.
+
+@item @code{verbose?} (default: @code{#f})
+Whether to enable logging.
+@end table
+@end deftp
+
 @node Guix Home Services
 @subsection Guix Home Services
 
diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
index b0f4d969b0..20d0724055 100644
--- a/gnu/home/services/desktop.scm
+++ b/gnu/home/services/desktop.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 ( <paren@disroot.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -20,6 +21,7 @@ (define-module (gnu home services desktop)
   #:use-module (gnu home services)
   #:use-module (gnu home services shepherd)
   #:use-module (gnu services configuration)
+  #:autoload   (gnu packages glib)    (dbus)
   #:autoload   (gnu packages xdisorg) (redshift)
   #:use-module (guix records)
   #:use-module (guix gexp)
@@ -27,8 +29,10 @@ (define-module (gnu home services desktop)
   #:use-module (ice-9 match)
   #:export (home-redshift-configuration
             home-redshift-configuration?
+            home-redshift-service-type
 
-            home-redshift-service-type))
+            home-dbus-configuration
+            home-dbus-service-type))
 
 
 ;;;
@@ -172,3 +176,55 @@ (define home-redshift-service-type
    (description
     "Run Redshift, a program that adjusts the color temperature of display
 according to time of day.")))
+
+
+;;;
+;;; D-Bus.
+;;;
+
+(define-record-type* <home-dbus-configuration>
+  home-dbus-configuration make-home-dbus-configuration
+  home-dbus-configuration?
+  (dbus home-dbus-dbus                  ;file-like
+        (default dbus))
+  (verbose? home-dbus-verbose?          ;boolean
+            (default #f)))
+
+(define (home-dbus-shepherd-services config)
+  (list (shepherd-service
+         (documentation "Run the D-Bus daemon in session-specific mode.")
+         (provision '(dbus-session))
+         (start #~(make-forkexec-constructor
+                   (list #$(file-append (home-dbus-dbus config)
+                                        "/bin/dbus-daemon")
+                         "--nofork" "--session"
+                         (format #f "--address=unix:path=~a/bus"
+                                 (or (getenv "XDG_RUNTIME_DIR")
+                                     (format #f "/run/user/~a"
+                                             (getuid)))))
+                   #$@(if (home-dbus-verbose? config)
+                          (list #:environment-variables
+                                #~(list "DBUS_VERBOSE=1")
+                                #:log-file
+                                (format #f "~a/dbus-daemon.log"
+                                        (or (getenv "XDG_LOG_HOME")
+                                            (format #f "~a/.local/var/log"
+                                                    (getenv "HOME")))))
+                          '())))
+         (stop #~(make-kill-destructor)))))
+
+(define (home-dbus-environment-variables config)
+  '(("DBUS_SESSION_BUS_ADDRESS"
+     . "unix:path=${XDG_RUNTIME_DIR:-/run/user/$UID}/bus")))
+
+(define home-dbus-service-type
+  (service-type
+   (name 'home-dbus)
+   (extensions
+    (list (service-extension home-shepherd-service-type
+                             home-dbus-shepherd-services)
+          (service-extension home-environment-variables-service-type
+                             home-dbus-environment-variables)))
+   (default-value (home-dbus-configuration))
+   (description
+    "Run the session-specific D-Bus inter-process message bus.")))
-- 
2.38.0