all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrew Tropin <andrew@trop.in>
To: Taiju HIGASHI <higashi@taiju.info>, 57963@debbugs.gnu.org
Cc: ludo@gnu.org, Taiju HIGASHI <higashi@taiju.info>,
	liliana.prikler@gmail.com
Subject: [bug#57963] [PATCH v5 2/2] home: services: Support user's fontconfig configuration.
Date: Mon, 10 Oct 2022 10:40:30 +0400	[thread overview]
Message-ID: <87zge4chb5.fsf@trop.in> (raw)
In-Reply-To: <20221002131535.9972-2-higashi@taiju.info>

[-- Attachment #1: Type: text/plain, Size: 6643 bytes --]

On 2022-10-02 22:15, Taiju HIGASHI wrote:

> * gnu/home/services/fontutils.scm (add-fontconfig-config-file): Support user's
> fontconfig configuration.
> (home-fontconfig-configuration): New configuration for it.
> (string-list, maybe-string, maybe-extra-config-list): New types for it.
> (string-list?, extra-config-list?): New predicate procedures for it.
> (serialize-string-list, serialize-string, serialize-extra-config-list): New
> serialize procedures for it.
> (guix-home-font-dir): New variable.
> ---
>  gnu/home/services/fontutils.scm | 89 ++++++++++++++++++++++++++++++---
>  1 file changed, 83 insertions(+), 6 deletions(-)
>
> diff --git a/gnu/home/services/fontutils.scm b/gnu/home/services/fontutils.scm
> index 6062eaed6a..4b3caf3985 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 <andrew@trop.in>
>  ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
> +;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -20,9 +21,17 @@
>  (define-module (gnu home services fontutils)
>    #:use-module (gnu home services)
>    #:use-module (gnu packages fontutils)
> +  #:use-module (gnu services configuration)
> +  #:use-module (guix diagnostics)
>    #:use-module (guix gexp)
> +  #:use-module (guix i18n)
> +  #:use-module (guix records)
> +  #:use-module (srfi srfi-1)
> +  #:use-module (sxml simple)
> +  #:use-module (ice-9 match)
>  
> -  #:export (home-fontconfig-service-type))
> +  #:export (home-fontconfig-service-type
> +            home-fontconfig-configuration))
>  
>  ;;; Commentary:
>  ;;;
> @@ -33,15 +42,83 @@ (define-module (gnu home services fontutils)
>  ;;;
>  ;;; Code:
>  
> -(define (add-fontconfig-config-file he-symlink-path)
> +(define (sxml->xml-string sxml)
> +  "Serialize the sxml tree @var{tree} as XML. The output will be string."
> +  (call-with-output-string
> +    (lambda (port)
> +      (sxml->xml sxml port))))
> +
> +(define guix-home-font-dir "~/.guix-home/profile/share/fonts")
> +
> +(define (string-list? value)
> +  (and (pair? value) (every string? value)))

Better to use list? here and in the other places, at least for the
consistency, but also for semantic meaning.

> +
> +(define (serialize-string-list field-name value)
> +  (sxml->xml-string
> +   (map
> +    (lambda (path) `(dir ,path))
> +    (if (member guix-home-font-dir value)
> +        value
> +        (append (list guix-home-font-dir) value)))))
> +
> +(define (serialize-string field-name value)
> +  (define (serialize type value)
> +    (sxml->xml-string
> +     `(alias
> +       (family ,type)
> +       (prefer
> +        (family ,value)))))
> +  (match (list field-name value)
> +    (('default-font-serif-family family)
> +     (serialize 'serif family))
> +    (('default-font-sans-serif-family family)
> +     (serialize 'sans-serif family))
> +    (('default-font-monospace-family family)
> +     (serialize 'monospace family))))
> +
> +(define-maybe string)
> +
> +(define extra-config-list? list?)
> +
> +(define-maybe extra-config-list)
> +
> +(define (serialize-extra-config-list field-name value)
> +  (sxml->xml-string
> +   (map (match-lambda
> +          ((? pair? sxml) sxml)

Other branches would never be visited because it will fail earlier by
define-configuration predicate check for extra-config-list? (which is
basically list?).

Also, making multi-type fields is debatable, but isn't great IMO.

If serialization would support G-exps, we could write 

(list #~"RAW_XML_HERE")

or even something like this:

(list #~(READ-THE-WHOLE-FILE #$(local-file "our-old.xml")))

> +          ((? string? xml) (xml->sxml xml))
> +          (else
> +           (raise (formatted-message
> +                   (G_ "'extra-config' type must be xml string or sxml list, was given: ~a")
> +                   value))))
> +        value)))
> +
> +(define-configuration home-fontconfig-configuration
> +  (font-directories
> +   (string-list (list guix-home-font-dir))

It's not a generic string-list, but a specific font-directories-list
with extra logic inside.

Also, because guix-home-font-dir always added to the list, the default
value should '() and field should be called additional-font-directories
instead.  Otherwise it will be confusing, why guix-home-font-dir is not
removed from the final configuration, when this field is set to a
different value.

I skimmed previous messages, but sorry, if I missed any already
mentioned points.

> +   "The directory list that provides fonts.")
> +  (default-font-serif-family
> +    maybe-string
> +    "The preffered default fonts of serif.")
> +  (default-font-sans-serif-family
> +    maybe-string
> +    "The preffered default fonts of sans-serif.")
> +  (default-font-monospace-family
> +    maybe-string
> +    "The preffered default fonts of monospace.")
> +  (extra-config
> +   maybe-extra-config-list
> +   "Extra configuration values to append to the fonts.conf."))
> +
> +(define (add-fontconfig-config-file 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>"))))
> +<fontconfig>"
> +       (serialize-configuration user-config home-fontconfig-configuration-fields)

Just a thought for the future and a point for configuration module
improvements: It would be cool if serialize-configuration and all other
serialize- functions returned a G-exps, this way we could write
something like that:

(home-fontconfig-configuration
 (font-directories (list (file-append font-iosevka "/share/fonts"))))

> +       "</fontconfig>\n"))))
>  
>  (define (regenerate-font-cache-gexp _)
>    `(("profile/share/fonts"
> @@ -59,7 +136,7 @@ (define home-fontconfig-service-type
>                         (service-extension
>                          home-profile-service-type
>                          (const (list fontconfig)))))
> -                (default-value #f)
> +                (default-value (home-fontconfig-configuration))
>                  (description
>                   "Provides configuration file for fontconfig and make
>  fc-* utilities aware of font packages installed in Guix Home's profile.")))

-- 
Best regards,
Andrew Tropin

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2022-10-10  6:41 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21  0:27 [bug#57963] [PATCH 0/1] Support user's fontconfig Taiju HIGASHI
2022-09-21  0:29 ` [bug#57963] [PATCH 1/1] home: fontutils: " Taiju HIGASHI
2022-09-21  8:54   ` Liliana Marie Prikler
2022-09-21  9:59     ` Taiju HIGASHI
2022-09-21 11:40       ` Liliana Marie Prikler
2022-09-22  1:27         ` Taiju HIGASHI
2022-09-23  7:20           ` Liliana Marie Prikler
2022-09-22  1:20 ` [bug#57963] [PATCH v2] " Taiju HIGASHI
2022-09-22  6:14   ` Andrew Tropin
2022-09-22  8:53     ` Ludovic Courtès
2022-09-22  9:50       ` Taiju HIGASHI
2022-09-24 15:52         ` [bug#57963] [PATCH 0/1] " Ludovic Courtès
2022-09-24 22:58           ` Taiju HIGASHI
2022-09-25  6:25             ` Liliana Marie Prikler
2022-09-25  7:29               ` Taiju HIGASHI
2022-09-25  7:34                 ` Taiju HIGASHI
2022-09-25 15:50                 ` Liliana Marie Prikler
2022-09-26  1:43                   ` Taiju HIGASHI
2022-09-26 18:19                     ` Liliana Marie Prikler
2022-09-27  9:55 ` [bug#57963] [PATCH v3] home: fontutils: " Taiju HIGASHI
2022-09-27 10:10   ` Taiju HIGASHI
2022-09-28 21:15     ` [bug#57963] [PATCH 0/1] " Ludovic Courtès
2022-09-29  1:01       ` Taiju HIGASHI
2022-09-29 14:28         ` Ludovic Courtès
2022-09-29 14:51           ` Taiju HIGASHI
2022-09-29 16:02             ` ( via Guix-patches via
2022-09-30  0:12               ` Taiju HIGASHI
2022-09-30 18:30             ` liliana.prikler
2022-10-01 11:11               ` Taiju HIGASHI
2022-09-28 19:11   ` [bug#57963] [PATCH v3] home: fontutils: " Liliana Marie Prikler
2022-09-29  0:31     ` Taiju HIGASHI
2022-09-29 14:46       ` Taiju HIGASHI
2022-09-29 14:36 ` [bug#57963] [PATCH v4 1/2] home-services: Add base Taiju HIGASHI
2022-09-29 14:36   ` [bug#57963] [PATCH v4 2/2] home: fontutils: Support user's fontconfig Taiju HIGASHI
2022-09-29 14:55     ` Taiju HIGASHI
2022-09-30 18:34     ` liliana.prikler
2022-10-01 11:19       ` Taiju HIGASHI
2022-10-01 16:14         ` liliana.prikler
2022-10-02 13:22           ` Taiju HIGASHI
2022-10-01 21:57     ` Ludovic Courtès
2022-10-02 13:38       ` Taiju HIGASHI
2022-09-29 14:43   ` [bug#57963] [PATCH v4 1/2] home-services: Add base Liliana Marie Prikler
2022-09-29 15:09     ` Taiju HIGASHI
2022-09-30 18:21       ` liliana.prikler
2022-10-01 11:08         ` Taiju HIGASHI
2022-10-01 21:47   ` Ludovic Courtès
2022-10-02 13:45     ` Taiju HIGASHI
2022-10-02 14:59       ` Liliana Marie Prikler
2022-10-03 23:27         ` Taiju HIGASHI
2022-10-10  5:50         ` Andrew Tropin
2022-10-02 13:12 ` [bug#57963] [PATCH v5 1/2] home: services: " Taiju HIGASHI
2022-10-02 13:20   ` Taiju HIGASHI
2022-10-02 13:15 ` Taiju HIGASHI
2022-10-02 13:15   ` [bug#57963] [PATCH v5 2/2] home: services: Support user's fontconfig configuration Taiju HIGASHI
2022-10-10  6:40     ` Andrew Tropin [this message]
2022-10-10 16:15       ` Liliana Marie Prikler
2022-10-12  6:05         ` Andrew Tropin
2022-10-11  3:54       ` Taiju HIGASHI
2022-10-11  4:21         ` Liliana Marie Prikler
2022-10-11  8:09           ` Taiju HIGASHI
2022-10-11 18:24             ` Liliana Marie Prikler
2022-10-12  3:59               ` Taiju HIGASHI
2022-10-12  4:21                 ` Liliana Marie Prikler
2022-10-12  7:07           ` [bug#57963] Almost plain SXML serializer Andrew Tropin
2022-10-12 11:42             ` Taiju HIGASHI
2022-10-12 13:03               ` Andrew Tropin
2022-10-12 18:23                 ` Liliana Marie Prikler
2022-10-13  3:51                   ` Andrew Tropin
2022-10-12  6:43         ` [bug#57963] [PATCH v5 2/2] home: services: Support user's fontconfig configuration Andrew Tropin
2022-10-12 11:38           ` Taiju HIGASHI
2022-10-12 12:41             ` Andrew Tropin
2022-10-13 12:37       ` Ludovic Courtès
2022-10-14  5:06         ` Andrew Tropin
2022-10-15 11:13           ` Taiju HIGASHI
2022-10-17 16:28             ` Ludovic Courtès
2022-10-18 12:41               ` Taiju HIGASHI
2022-10-19 21:42                 ` Taiju HIGASHI
2022-10-20  1:23                   ` [bug#57963] [PATCH 0/1] Support user's fontconfig Declan Tsien
2022-10-20  1:37                     ` Taiju HIGASHI
2022-10-20  2:03                       ` Declan Tsien
2022-10-20  3:44                         ` Taiju HIGASHI
2022-10-20  5:06                           ` Declan Tsien
2022-10-21  1:02                             ` Taiju HIGASHI
2022-10-27  4:00                   ` [bug#57963] [PATCH v5 2/2] home: services: Support user's fontconfig configuration Taiju HIGASHI
2022-10-27  5:18                     ` Liliana Marie Prikler
2022-10-27  5:31                       ` Taiju HIGASHI
2022-10-27  6:36                         ` Liliana Marie Prikler
2022-11-02  1:43                           ` Taiju HIGASHI
2022-11-02  6:45                             ` Liliana Marie Prikler
2022-11-04  8:46                               ` Taiju HIGASHI
2022-11-04 16:29                                 ` ( via Guix-patches via
2022-11-06 13:24                                   ` Taiju HIGASHI
2022-10-20  5:40     ` Declan Tsien
2022-10-21  4:03       ` Taiju HIGASHI
2022-10-21  5:02         ` Declan Tsien
2022-10-21  8:01           ` Taiju HIGASHI
2022-10-21  9:15             ` Declan Tsien
2022-10-23  6:32               ` Taiju HIGASHI
2022-10-23  7:33                 ` Declan Tsien
2022-10-23 11:40                   ` Taiju HIGASHI
2022-10-07  5:20 ` [bug#57963] Next steps for this issue Taiju HIGASHI
2022-10-07  5:44   ` Taiju HIGASHI

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=87zge4chb5.fsf@trop.in \
    --to=andrew@trop.in \
    --cc=57963@debbugs.gnu.org \
    --cc=higashi@taiju.info \
    --cc=liliana.prikler@gmail.com \
    --cc=ludo@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.