From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.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 UD3rIqu+Q2MTZgAAbAwnHQ (envelope-from ) for ; Mon, 10 Oct 2022 08:41:47 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id SKgQIqu+Q2OxRQAAG6o9tA (envelope-from ) for ; Mon, 10 Oct 2022 08:41:47 +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 0876F7C59 for ; Mon, 10 Oct 2022 08:41:47 +0200 (CEST) Received: from localhost ([::1]:54542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohmTy-00061R-4n for larch@yhetil.org; Mon, 10 Oct 2022 02:41:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohmTG-0005zA-SH for guix-patches@gnu.org; Mon, 10 Oct 2022 02:41:07 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohmTG-0001xR-Jt for guix-patches@gnu.org; Mon, 10 Oct 2022 02:41:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ohmTG-0003ng-EY for guix-patches@gnu.org; Mon, 10 Oct 2022 02:41:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57963] [PATCH v5 2/2] home: services: Support user's fontconfig configuration. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 10 Oct 2022 06:41: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: Taiju HIGASHI , 57963@debbugs.gnu.org Cc: ludo@gnu.org, Taiju HIGASHI , liliana.prikler@gmail.com Received: via spool by 57963-submit@debbugs.gnu.org id=B57963.166538405114584 (code B ref 57963); Mon, 10 Oct 2022 06:41:02 +0000 Received: (at 57963) by debbugs.gnu.org; 10 Oct 2022 06:40:51 +0000 Received: from localhost ([127.0.0.1]:45545 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ohmT5-0003nA-1J for submit@debbugs.gnu.org; Mon, 10 Oct 2022 02:40:51 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:34443) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ohmT1-0003mu-7B for 57963@debbugs.gnu.org; Mon, 10 Oct 2022 02:40:49 -0400 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id F0FE340004; Mon, 10 Oct 2022 06:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1665384041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eCpzUZ5YJPyFCWLfXiJHe3QfZwMrQnmxG4S0zJmXwhE=; b=j2NyPn+ld2Bljg4BIxI3MJyl78hoQvyTFRoCJVYrLxn7a/UYYCTjrPOsSRrC14AcgrFD7c PyACGlBI/NQ2ij+O71LGdliWPNIVPUb5ktMLQxbAxFJMgPxolK9i+ZLt3JmpCh9H2k+tN5 CPSm2b1Oq34YZ0a5g45tyiVlZgKJxp3qMpiQszxFbZ2EaRKMtLJkDgtidGl4ki9ctgnDoK 2dLUlo8opGKLzmn7xDJc5D8ouLNJP9uVJhEh9c0m5CJ6JUVNR/Vrw/2cprHo+JDun23Lu1 q/ZqyFofpYOW7LueBLiaQ5u5Efa5EwDMnjsny48ENQYID7crTSH9ojrMdmWS0g== From: Andrew Tropin In-Reply-To: <20221002131535.9972-2-higashi@taiju.info> References: <20221002131535.9972-1-higashi@taiju.info> <20221002131535.9972-2-higashi@taiju.info> Date: Mon, 10 Oct 2022 10:40:30 +0400 Message-ID: <87zge4chb5.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" 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=1665384107; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: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=eCpzUZ5YJPyFCWLfXiJHe3QfZwMrQnmxG4S0zJmXwhE=; b=fVWWqeHJXvJglmGBhwxvOC9U/NNNXzep2Z26NSTeiz8MsOg3UfXKePtPJWmRYlKXw7TRd9 pbUVOM0dz1SAA3gOWuFd7jmr6Lfqd4Pu+Q0EVblfMjX1+FvFpARAQLYKpETZTB9cgvS4hQ WRkW0qm0Z85svbJg7o6lMWkiYlm6Pexi05lQYJ7f3v8rx/Sl17kR7VmLu6xaPm0bQuP6Me 42jii5GbOFZdoStCM1pZ1D9hDqNMKyb5lfsM3+d6nsccFpOtT4wfL9MadWMnG4LcdWv4MM 2Q+zvvNprTxWEw+Yv1UPKelw5DGeS7O1FjhRHazkcasYN7SQJDLf9o3rqQSEYg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665384107; a=rsa-sha256; cv=none; b=DlIfdBxRSys+/hQzfj/q+g5XBIg9BMRG/VbU2zDxCstd0dPMUkHUNs3nJp0XkC6koiV9AZ 9cxWh0wPjKh00CO/grD7yGF/J4aft5z6+K0tDlk84kjKA5ZluHQ+nRX0mI+0EgmBrv3NjX rxcJ7NzPCD2cdcs4hMAuZ80Pmhos1XrZ14JhMl4xAErS7ZI30oHme+PaUWDSCifIVyBG3x gZWk2jVizMtTqd1JpM615P2JxdLy3tBQ+P/Qu/oQPPh9G7ifTyfFn6j/QWST+WiCmnMEJU DJZ8bMuW67R9czjbNicKa0rqPeBYC3+gbN1msquaFXybUv9/caOuqnlEL7sPoA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=j2NyPn+l; dmarc=none; 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: 1.92 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=j2NyPn+l; dmarc=none; 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: 0876F7C59 X-Spam-Score: 1.92 X-Migadu-Scanner: scn1.migadu.com X-TUID: PbKeM8lRoTq2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2022-10-02 22:15, Taiju HIGASHI wrote: > * gnu/home/services/fontutils.scm (add-fontconfig-config-file): Support u= ser'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): N= ew > 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/fontutil= s.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 =C2=A9 2021 Andrew Tropin > ;;; Copyright =C2=A9 2021 Xinglu Chen > +;;; Copyright =C2=A9 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) >=20=20 > - #:export (home-fontconfig-service-type)) > + #:export (home-fontconfig-service-type > + home-fontconfig-configuration)) >=20=20 > ;;; Commentary: > ;;; > @@ -33,15 +42,83 @@ (define-module (gnu home services fontutils) > ;;; > ;;; Code: >=20=20 > -(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=20 (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 l= ist, 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" > " > > - > - ~/.guix-home/profile/share/fonts > -")))) > +" > + (serialize-configuration user-config home-fontconfig-configuratio= n-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")))) > + "\n")))) >=20=20 > (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."= ))) =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmNDvl4ACgkQIgjSCVjB 3rCueA/+PBM5g/Qe3+91C8u4h+s/0Ot6D9VJhBDQRLEgNYPkFKHKQ4dqsR0WQVHC QHpNmBlHp8cuh34q7UJ2YHMj+5MNzZK/iwekUu7eG0ioWTqTZe6dfVoq5ImPawgd 4f8CmcOFLRlmGD29EOjka9qkb7K8vHlBrOL3GBWiutLO7jmWgdlt3AcX6ehggqD7 8Jb5+aSwAcGl580RBMr/0SyTUqsvesyGjoRQn6T1AWZQI/2QRtYP6TAGlZ8TDbbr tYTU7Mgcvw9WkxjfpwK4JU6kDvp9e1I9HzfjlPfCgALOeYmpCjUWIAOSaouyZxXX JT5FmNXO+tY3Fra0SaD7CpyEF9JhtEnAgyPNECM35Ym/dP9mV/zaL4miZdJTC+Ef 2ItbOCHNU5LFWKXCOLLorKl+4D1o4Ux9csFrH9u/kHfxuZhJk8WKFW0IraMViXRN u4TF432subComkGGyBkoe5egCahVmD6CwqpQI0YMhje5vppN6bdjp5oY94oBoLuL MoibLZffrYmc4mTigrgzF7fA1+kg80Vm0SyOB3uVPgqokzXVJrp1vgRNVj2K0/NA 4Sq3hMPEknfLUgBktZI60C1OqFo6Eur1VAcq6DdOrJknpO2pd934gKveoFt39xcJ sXz9YgeU0kEU68FEdDo7pS732O6WCz/Q5HNkuAXyp9e1YtPz6yY= =ngCV -----END PGP SIGNATURE----- --=-=-=--