all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 58014@debbugs.gnu.org
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: [bug#58014] [PATCH 13/15] services: Add dconf-service-type.
Date: Fri, 23 Sep 2022 01:00:40 -0400	[thread overview]
Message-ID: <20220923050042.29893-13-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20220923050042.29893-1-maxim.cournoyer@gmail.com>

This allows the dconf profile directive "system-db:" to look up profiles by
name from under /etc/dconf/db/.

* gnu/services/xorg.scm (dconf-keyfile, dconf-profile): New procedures.
(dconf-profiles?): New predicate.
(dconf-configuration): New procedure.
(dconf-profile->profile-file): Likewise.
(dconf-profile->db-keyfile): Likewise.
(dconf-profile->db-keyfile-dir): Likewise.
(dconf-profile->db): Likewise.
(dconf-profile->files): Likewise.
(dconf-service-type): New service type.
---
 gnu/services/xorg.scm | 109 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)

diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm
index eb77822741..9205c6f9f4 100644
--- a/gnu/services/xorg.scm
+++ b/gnu/services/xorg.scm
@@ -12,6 +12,7 @@
 ;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
 ;;; Copyright © 2021 Josselin Poiret <josselin.poiret@protonmail.ch>
 ;;; Copyright © 2022 Chris Marusich <cmmarusich@gmail.com>
+;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -32,6 +33,7 @@ (define-module (gnu services xorg)
   #:autoload   (gnu services sddm) (sddm-service-type)
   #:use-module (gnu artwork)
   #:use-module (gnu services)
+  #:use-module (gnu services configuration)
   #:use-module (gnu services shepherd)
   #:use-module (gnu system pam)
   #:use-module (gnu system setuid)
@@ -114,6 +116,13 @@ (define-module (gnu services xorg)
             localed-configuration?
             localed-service-type
 
+            dconf-keyfile
+            dconf-profile
+            dconf-profile-name
+            dconf-profile-content
+            dconf-profile-keyfile
+            dconf-service-type
+
             gdm-configuration
             gdm-service-type
 
@@ -803,6 +812,106 @@ (define localed-service-type
 the GNOME desktop environment.")
                   (default-value (localed-configuration)))))
 
+\f
+;;;
+;;; Dconf.
+;;;
+
+(define-maybe text-config)
+
+(define-configuration/no-serialization dconf-keyfile
+  (name string
+        "The file name of the associated keyfile, e.g. \"00-login-screen\".")
+  (content text-config "The content of the associated keyfile."))
+
+(define-configuration/no-serialization dconf-profile
+  (name string "The file name of the dconf system profile, which should match
+the name of a user for which the profile is to be used with.  To have the
+profile used, the environment variable \"DCONF_PROFILE\" should be set to the
+profile file, e.g.:
+@example
+ export DCONF_PROFILE=/etc/dconf/profile/gdm
+@end example")
+  (content maybe-text-config "The content of the Dconf profile.  Unless
+provided, it defaults to include the user database (\"user-db:NAME\") as well
+as the system database (\"system-db:NAME\"), which corresponds to the
+generated database, @file{/etc/dconf/db/NAME}.")
+  (keyfile dconf-keyfile "The keyfile associated with the profile"))
+
+(define dconf-profiles?
+  (list-of dconf-profile?))
+
+(define-configuration/no-serialization dconf-configuration
+  (profiles dconf-profiles "The list of <dconf-profile> objects to populate."))
+
+(define (dconf-profile->profile-file profile)
+  "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
+  (let ((name (dconf-profile-name profile))
+        (content (dconf-profile-content profile)))
+    (apply mixed-text-file
+           name
+           (if (maybe-value-set? content)
+               (interpose content "\n" 'suffix)
+               (interpose (list (string-append "user-db:" name)
+                                (string-append "system-db:" name))
+                          "\n" 'suffix)))))
+
+(define (dconf-profile->db-keyfile profile)
+  "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
+  (let ((keyfile (dconf-profile-keyfile profile)))
+    (apply mixed-text-file (dconf-keyfile-name keyfile)
+           (interpose (dconf-keyfile-content keyfile) "\n" 'suffix))))
+
+(define (dconf-profile->db-keyfile-dir profile)
+  "Wrap the keyfile in a directory, to satisfy 'dconf compile'."
+  (let ((name (dconf-profile-name profile))
+        (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
+    (computed-file name
+                   #~(begin
+                       (mkdir #$output)
+                       (symlink #$(dconf-profile->db-keyfile profile)
+                                (string-append #$output "/" #$keyfile-name))))))
+
+(define (dconf-profile->db profile)
+  "Compile the a <dconf-profile> object into a GVariant Database file."
+  (let ((name (dconf-profile-name profile)))
+    (computed-file
+     name
+     (with-imported-modules '((guix build utils))
+       #~(begin
+           (use-modules (guix build utils))
+           (setenv "DCONF_PROFILE" #$(dconf-profile->profile-file profile))
+           (invoke #$(file-append dconf "/bin/dconf") "compile"
+                   #$output #$(dconf-profile->db-keyfile-dir profile)))))))
+
+(define (dconf-profile->files profile)
+  "Given PROFILE, a <dconf-profile> object, return a dconf directory
+containing the associated profile, keyfile and database files to be assembled
+under /etc."
+  (let ((name (dconf-profile-name profile))
+        (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
+    (list (list (string-append "dconf/profile/" name)
+                (dconf-profile->profile-file profile))
+          (list (string-append "dconf/db/" name ".d/" keyfile-name)
+                (dconf-profile->db-keyfile profile))
+          (list (string-append "dconf/db/" name)
+                (dconf-profile->db profile)))))
+
+(define dconf-service-type
+  (service-type
+   (name 'dconf-profile)
+   (extensions
+    (list (service-extension etc-service-type
+                             (lambda (dconf-profiles)
+                               (append-map dconf-profile->files
+                                           dconf-profiles)))))
+   (compose concatenate)
+   (extend append)
+   (default-value '())
+   (description "Extend the @code{etc-service-type} to populate the file
+hierarchy under @file{/etc/dconf} with the <dconf-profile> objects provided as
+argument.")))
+
 \f
 ;;;
 ;;; GNOME Desktop Manager.
-- 
2.37.3





  parent reply	other threads:[~2022-09-23  5:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23  4:58 [bug#58014] [PATCH 00/15] Add xvnc-service-type Maxim Cournoyer
2022-09-23  5:00 ` [bug#58014] [PATCH 01/15] gnu: tigervnc-server: Use new style inputs, gexps Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 02/15] gnu: tigervnc-server: Move source production into origin snippet Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 03/15] gnu: tigervnc-server: Adjust PAM config Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 04/15] gnu: tigervnc-server: Disable tests via #:tests? Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 05/15] gnu: tigervnc-server: Patch and wrap vncserver script Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 06/15] gnu: gdm: Patch an extra reference to the Xsession script Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 07/15] services: gdm: Add a configuration field to enable XDMCP Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 08/15] marionette: Make marionette-screen-text private Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 09/15] marionette: Preserve screen dumps on failures Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 10/15] marionette: Define keystrokes for typing colons and exclamation marks Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 11/15] marionette: Add a callback arguments to wait-for-screen-text Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 12/15] gnu: dconf: Set sysconfdir to /etc Maxim Cournoyer
2022-09-23  5:00   ` Maxim Cournoyer [this message]
2022-09-23  5:00   ` [bug#58014] [PATCH 14/15] services: xorg: Add auto-suspend? field to <gdm-configuration> Maxim Cournoyer
2022-09-23  5:00   ` [bug#58014] [PATCH 15/15] services: Add xvnc-service-type Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220923050042.29893-13-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=58014@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.