From patchwork Sun Oct 2 13:15:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taiju HIGASHI X-Patchwork-Id: 43111 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 106E227BBEB; Sun, 2 Oct 2022 14:16:19 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D6BB627BBE9 for ; Sun, 2 Oct 2022 14:16:17 +0100 (BST) Received: from localhost ([::1]:37498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeypM-0000O4-Q0 for patchwork@mira.cbaines.net; Sun, 02 Oct 2022 09:16:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeyp9-0000L8-1D for guix-patches@gnu.org; Sun, 02 Oct 2022 09:16:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oeyp8-000396-Mp for guix-patches@gnu.org; Sun, 02 Oct 2022 09:16:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oeyp8-0008D2-H9 for guix-patches@gnu.org; Sun, 02 Oct 2022 09:16:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57963] [PATCH v5 2/2] home: services: Support user's fontconfig configuration. Resent-From: Taiju HIGASHI Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 02 Oct 2022 13:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57963 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 57963@debbugs.gnu.org Cc: ludo@gnu.org, Taiju HIGASHI , liliana.prikler@gmail.com, andrew@trop.in Received: via spool by 57963-submit@debbugs.gnu.org id=B57963.166471656131535 (code B ref 57963); Sun, 02 Oct 2022 13:16:02 +0000 Received: (at 57963) by debbugs.gnu.org; 2 Oct 2022 13:16:01 +0000 Received: from localhost ([127.0.0.1]:46502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeyp7-0008CQ-Br for submit@debbugs.gnu.org; Sun, 02 Oct 2022 09:16:01 -0400 Received: from mail-pl1-f173.google.com ([209.85.214.173]:45862) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeyp4-0008C0-Cp for 57963@debbugs.gnu.org; Sun, 02 Oct 2022 09:15:59 -0400 Received: by mail-pl1-f173.google.com with SMTP id u24so635383plq.12 for <57963@debbugs.gnu.org>; Sun, 02 Oct 2022 06:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=taiju-info.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=IoHeb2pHkDjy0aw5l7LvutHwtBqqe7doznlxEpcU0Dw=; b=GgTjn5ljfLkxE/XCswtQXOsWZUu7oqHYytOz09s+NznnIeTWrcKwkmI1zI7hYIynBZ 0uOjEEU6JV5ohWhX3rVhkwep5aI3ZEvIJPG711Mlu32YbROeqjNUqQYdQAGvHlqPjmtW /HbhNihigVHO9jgjnWYfMNX5eyRDza1/id7v6UQc6Er46xAf/w5stINz5hCKfSzSIqDI 61A4YcR6HQ8DrFBBqsvUanlt3ryBUT2GfNyRpxHMj3tlH9dzoG1bhEePgsm7Ra1Gb6Be Tbb2rX2e3ugSIBPAdaI/rOw2Xz6nrqdj+/TclxnvBGsfBM89kP8/ti1zFxDP3Z5EPRMf lVxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=IoHeb2pHkDjy0aw5l7LvutHwtBqqe7doznlxEpcU0Dw=; b=SMbopuSY8mxjny0Us2geS9V1p7lM4BF4LeA/Hf5wq98y/9Xlmb8FK0PAzEAxr/S4p+ m2iI6ul/2q91Rie0PYATdvtsworrQNHt9m5IXTK26GDrldb/rnNuKG/Vy57z3WD+jt17 cE/U842236EOiAgePkEs2MChLfGYKqK5tT4p5fd7mXGpKn3r0W0zbsyt2w3rF1FkBFEB 9+CMgDiJ/yGw1zpbrZ98qocd9Nx6GUFaNs9LFcXB8Hce9uz/07u3u1QGc8Cz0aB6xPk0 YkPNeAlPEWlvBHdXk/k0am/vP/EHQAHCV3kaOXjuZXvCnbbBW2EunxFQCJaMW4G/y7Dc cmCQ== X-Gm-Message-State: ACrzQf1j4PVPjCpFYGPFJQc/bJQ6IO4tMmKi0p9Jb9BzY7UsJJ6k9fXW vB1KiYoYjs2fXZyf91e7V6Wr20Z8YmRZ4z2y X-Google-Smtp-Source: AMsMyM49DuD3ay4rsWw7WklKTrn1bEPKnVmt+iwOwBJ0EKDCW9jkwSJOoZ1lHzKRUajAidCfdBPXhQ== X-Received: by 2002:a17:903:1c4:b0:17f:5b7b:657 with SMTP id e4-20020a17090301c400b0017f5b7b0657mr651090plh.125.1664716552499; Sun, 02 Oct 2022 06:15:52 -0700 (PDT) Received: from Taix.flets-west.jp ([240b:253:ec40:2400:b7d1:436e:2d61:e925]) by smtp.gmail.com with ESMTPSA id i2-20020a17090332c200b00176c89243fcsm5342906plr.179.2022.10.02.06.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 06:15:52 -0700 (PDT) From: Taiju HIGASHI Date: Sun, 2 Oct 2022 22:15:35 +0900 Message-Id: <20221002131535.9972-2-higashi@taiju.info> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221002131535.9972-1-higashi@taiju.info> References: <20221002131535.9972-1-higashi@taiju.info> MIME-Version: 1.0 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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 ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Taiju HIGASHI ;;; ;;; 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))) + +(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) + ((? 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)) + "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" " - - ~/.guix-home/profile/share/fonts -")))) +" + (serialize-configuration user-config home-fontconfig-configuration-fields) + "\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.")))