Subject: [bug#57963] [PATCH v2] home: fontutils: Support user's fontconfig.

From: Taiju HIGASHI <[email-masked]>
Date: Thu, 22 Sep 2022 10:20:33 +0900

* gnu/home/services/fontutils.scm (add-fontconfig-config-file): Support user's
fontconfig.
---
 gnu/home/services/fontutils.scm | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/gnu/home/services/fontutils.scm b/gnu/home/services/fontutils.scm
index 6062eaed6a..b57cccbaae 100644
--- a/gnu/home/services/fontutils.scm
+++ b/gnu/home/services/fontutils.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Andrew Tropin <[email-masked]>
 ;;; Copyright © 2021 Xinglu Chen <[email-masked]>
+;;; Copyright © 2022 Taiju HIGASHI <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -21,6 +22,9 @@ (define-module (gnu home services fontutils)
   #:use-module (gnu home services)
   #:use-module (gnu packages fontutils)
   #:use-module (guix gexp)
+  #:use-module (srfi srfi-1)
+  #:use-module (sxml simple)
+  #:use-module (ice-9 match)
 
   #:export (home-fontconfig-service-type))
 
@@ -33,15 +37,28 @@ (define-module (gnu home services fontutils)
 ;;;
 ;;; Code:
 
-(define (add-fontconfig-config-file he-symlink-path)
+(define (parse-extra-user-config extra-user-config)
+  (map (match-lambda
+         ((? pair? sxml) sxml)
+         ((? string? xml) (xml->sxml xml))
+         (_ (error "extra-user-config must be xml string or sxml.")))
+       extra-user-config))
+
+(define (add-fontconfig-config-file extra-user-config)
   `(("fontconfig/fonts.conf"
      ,(mixed-text-file
        "fonts.conf"
        "<?xml version='1.0'?>
 <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
-<fontconfig>
-  <dir>~/.guix-home/profile/share/fonts</dir>
-</fontconfig>"))))
+"
+       (call-with-output-string
+         (lambda (port)
+           (sxml->xml
+            `(fontconfig
+              (dir "~/.guix-home/profile/share/fonts")
+              ,@(parse-extra-user-config extra-user-config))
+            port)
+           (newline port)))))))
 
 (define (regenerate-font-cache-gexp _)
   `(("profile/share/fonts"
@@ -49,6 +66,8 @@ (define (regenerate-font-cache-gexp _)
 
 (define home-fontconfig-service-type
   (service-type (name 'home-fontconfig)
+                (compose concatenate)
+                (extend append)
                 (extensions
                  (list (service-extension
                         home-xdg-configuration-files-service-type
@@ -59,7 +78,7 @@ (define home-fontconfig-service-type
                        (service-extension
                         home-profile-service-type
                         (const (list fontconfig)))))
-                (default-value #f)
+                (default-value '())
                 (description
                  "Provides configuration file for fontconfig and make
 fc-* utilities aware of font packages installed in Guix Home's profile.")))
-- 
2.37.3