From patchwork Sun Mar 12 14:52:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Miguel_=C3=81ngel_Moreno?= X-Patchwork-Id: 47918 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 9B5E716D07; Sun, 12 Mar 2023 14:53:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED 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 158341685F for ; Sun, 12 Mar 2023 14:53:27 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pbN4K-0005sr-Ax; Sun, 12 Mar 2023 10:53:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbN4I-0005sS-Jw for guix-patches@gnu.org; Sun, 12 Mar 2023 10:53:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pbN4I-0002tP-Bf for guix-patches@gnu.org; Sun, 12 Mar 2023 10:53:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pbN4H-00005T-To for guix-patches@gnu.org; Sun, 12 Mar 2023 10:53:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62145] [PATCH] home: services: fontutils: Add font specifications. Resent-From: conses Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 12 Mar 2023 14:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62145 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62145@debbugs.gnu.org Cc: contact@conses.eu, Andrew Tropin X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.167863274832742 (code B ref -1); Sun, 12 Mar 2023 14:53:01 +0000 Received: (at submit) by debbugs.gnu.org; 12 Mar 2023 14:52:28 +0000 Received: from localhost ([127.0.0.1]:32948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pbN3j-0008W2-Ec for submit@debbugs.gnu.org; Sun, 12 Mar 2023 10:52:27 -0400 Received: from lists.gnu.org ([209.51.188.17]:46896) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pbN3h-0008Vu-Dv for submit@debbugs.gnu.org; Sun, 12 Mar 2023 10:52:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbN3f-0005rN-Er for guix-patches@gnu.org; Sun, 12 Mar 2023 10:52:23 -0400 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbN3c-0002ls-EW for guix-patches@gnu.org; Sun, 12 Mar 2023 10:52:23 -0400 Received: (Authenticated sender: contact@conses.eu) by mail.gandi.net (Postfix) with ESMTPSA id E365720002; Sun, 12 Mar 2023 14:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=conses.eu; s=gm1; t=1678632734; 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: content-transfer-encoding:content-transfer-encoding; bh=5h8YW0blDC5aW1ooLSD4VmzNl/R4XEhg2Y75tyZoV4E=; b=JOoVQ5hPHsUQGuO3Czn6tx8Ykr/CM/dWFMBkozZKuol3OR1Cs8Mb8z0ptIX5SuWqvWPrGA oipjgS90eBfg0RyFxfW+WdquZPh0e5R1rdlHVjdAcXUbb881wz5ul7En2dyZfjeDpk6K/5 odmwyVLkw4KKlK9J9UqDUm9xgm0lkwV/12Ueb4t1R6z5xgXp4Y7vMtg7s+DuNVzuKvn7ox 3Jxpb8SyQNDJS7xW2hJRB7TcQ7s37sHsxmnjtzVfZihlec/6lVrHAIBc24r6f02AXq0kmB uZ1XrFz8CNa+DdacAmIJQeMNUeFkdA1I7AxH0wtcGZEOcb1wBdbPMhwtLEgMrQ== From: conses Date: Sun, 12 Mar 2023 15:52:12 +0100 Message-ID: <86jzzmt42r.fsf@conses.eu> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4b98:dc4:8::227; envelope-from=contact@conses.eu; helo=relay7-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/home/services/fontutils.scm (add-font-profile-packages): Install font packages for font spec families; (home-fontconfig-configuration): New variable; (add-fontconfig-config-files): Serialize with new values; (add-fontconfig-extensions): New variable; (home-fontconfig-service-type): Honor it. --- gnu/home/services/fontutils.scm | 100 ++++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 12 deletions(-) diff --git a/gnu/home/services/fontutils.scm b/gnu/home/services/fontutils.scm index 3399cb7ec8..4b1681c7d7 100644 --- a/gnu/home/services/fontutils.scm +++ b/gnu/home/services/fontutils.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2023 Giacomo Leidi +;;; Copyright © 2023 conses ;;; ;;; This file is part of GNU Guix. ;;; @@ -21,10 +22,18 @@ (define-module (gnu home services fontutils) #:use-module (gnu home services) #:use-module (gnu packages fontutils) + #:use-module (gnu services configuration) #:use-module (guix gexp) + #:use-module (guix records) #:use-module (srfi srfi-1) - #:export (home-fontconfig-service-type)) + #:export (home-fontconfig-service-type + home-fontconfig-configuration + font-spec + make-font-spec + font-spec? + font-spec-package + font-spec-family)) ;;; Commentary: ;;; @@ -35,37 +44,104 @@ (define-module (gnu home services fontutils) ;;; ;;; Code: -(define (add-fontconfig-config-file directories) +(define-record-type* + font-spec make-font-spec + font-spec? + (package font-spec-package) + (family font-spec-family)) + +(define (serialize-font-spec field-name val) + (string-append " +" (symbol->string field-name) " + + " (font-spec-family val) " + + +")) + +(define (serialize-list field val) + (apply string-append + (map (lambda (directory) + (string-append " " directory "\n")) + val))) + +(define-maybe font-spec) + +(define-configuration home-fontconfig-configuration + (sans-serif + (maybe-font-spec) + "Sans serif font.") + (serif + (maybe-font-spec) + "Serif font.") + (monospace + (maybe-font-spec) + "Monospace font.") + (directories + (list '("~/.guix-home/profile/share/fonts")) + "The directories to add to the default @code{fontconfig} configuration.")) + +(define (add-fontconfig-config-files config) `(("fontconfig/fonts.conf" ,(mixed-text-file "fonts.conf" - (apply string-append - `(" + " -\n" ,@(map (lambda (directory) - (string-append " " directory "\n")) - directories) - "\n")))))) + +" (serialize-configuration + config (filter-configuration-fields + home-fontconfig-configuration-fields '(directories))) + "\n")) + ("fontconfig/conf.d/50-default-fonts.conf" + ,(mixed-text-file + "50-user.conf" + " + + +" (serialize-configuration + config (filter-configuration-fields + home-fontconfig-configuration-fields '(directories) #t)) +" +")))) (define (regenerate-font-cache-gexp _) `(("profile/share/fonts" ,#~(system* #$(file-append fontconfig "/bin/fc-cache") "-fv")))) +(define (add-font-profile-packages config) + (append + (list fontconfig) + (fold (lambda (field res) + (let ((val ((configuration-field-getter field) config))) + (if (eq? 'disabled val) + res + (cons (font-spec-package val) res)))) + '() + (filter-configuration-fields + home-fontconfig-configuration-fields '(directories) #t)))) + +(define (add-fontconfig-extensions config extensions) + (home-fontconfig-configuration + (inherit config) + (directories + (append (home-fontconfig-configuration-directories config) + extensions)))) + (define home-fontconfig-service-type (service-type (name 'home-fontconfig) (extensions (list (service-extension home-xdg-configuration-files-service-type - add-fontconfig-config-file) + add-fontconfig-config-files) (service-extension home-run-on-change-service-type regenerate-font-cache-gexp) (service-extension home-profile-service-type - (const (list fontconfig))))) + add-font-profile-packages))) (compose concatenate) - (extend append) - (default-value '("~/.guix-home/profile/share/fonts")) + (extend add-fontconfig-extensions) + (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.")))