From patchwork Thu Apr 13 03:40:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Patterson X-Patchwork-Id: 49135 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 98339174FC; Thu, 13 Apr 2023 04:42:30 +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=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=ham 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 1F227174F1 for ; Thu, 13 Apr 2023 04:42:22 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmnqY-0008Lf-3s; Wed, 12 Apr 2023 23:42:06 -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 1pmnqX-0008LR-0H for guix-patches@gnu.org; Wed, 12 Apr 2023 23:42:05 -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 1pmnqV-0005rO-U8; Wed, 12 Apr 2023 23:42:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pmnqV-0003dK-8k; Wed, 12 Apr 2023 23:42:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62806] [PATCH] gnu: home: services: fontutils: Add support for SXML fragments. Resent-From: Andrew Patterson Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, guix-patches@gnu.org Resent-Date: Thu, 13 Apr 2023 03:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62806 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62806@debbugs.gnu.org Cc: Andrew Patterson , ludo@gnu.org X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: ludo@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.168135727913911 (code B ref -1); Thu, 13 Apr 2023 03:42:02 +0000 Received: (at submit) by debbugs.gnu.org; 13 Apr 2023 03:41:19 +0000 Received: from localhost ([127.0.0.1]:42245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pmnpm-0003cI-8T for submit@debbugs.gnu.org; Wed, 12 Apr 2023 23:41:19 -0400 Received: from lists.gnu.org ([209.51.188.17]:38136) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pmnpg-0003c4-LJ for submit@debbugs.gnu.org; Wed, 12 Apr 2023 23:41:14 -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 1pmnpf-0008I6-58 for guix-patches@gnu.org; Wed, 12 Apr 2023 23:41:11 -0400 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmnpb-0005fP-Nc for guix-patches@gnu.org; Wed, 12 Apr 2023 23:41:10 -0400 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-54c12009c30so365596027b3.9 for ; Wed, 12 Apr 2023 20:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681357264; x=1683949264; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mbPTcNq61I5k7DYWTQkKq7+Il/lnTaRizYBtqrv/ovg=; b=ZMZpWp93F/BFGFJhqYShdOTBdEew9MnSI/7oKJVP3PqqO/G+Ak5oAS4vVKdRfSuS5O qDa0rjMyFlZzS4urYUJswHL7vVaD7hoATecbDYCI55QlaBxbvCXwHpWOw/Y7OCMC4FV6 K2LhpMOp4L6L5GRLasXZXoEyHxFRQk0ZURX1EDpFmXOIzmqMD5SqIkZbeT2N7K0oavCR oG+7Pj/xben/6YllW3pUqyKkgsfLlGtzOao2MoKnkcOPak9I2hotJfy3uFd95Af+m2Gp Vi/tD2wNZHBtY9g9CXGiHMPVopBKuCV4LV690HQqDdrF7rxkOWYKpd7PMR3URqO9EWzk 7IuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681357264; x=1683949264; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mbPTcNq61I5k7DYWTQkKq7+Il/lnTaRizYBtqrv/ovg=; b=jHot0t9L5uXAyosqOeBGRworlTfEz0epxpaFn0PUB00hKruibPpu2+j4cRLFMm1d7z 9Vc1Q+f9Ey4vqQpfgwlL/Gab3rSYu2M3lRCX2zJjX3oqSTt73yO3dDLg31j0x9EBHpWF YQAIeKpClaQcFxi0lTRxt0RJ7zkhSRWaWUe87UXXLBDunHd06eWQFJioH5XB36sgAy/A fSLLkEzJhFJPsnrZdG5X9JPIWHfxyX0KjDwTkfWJ5T5VUlx8K9wn0dzHginOCesjpfFp wM7YsyevnzueoKqAs/YeKk0GiYDIi/iA199U81+15pBQJB5GsgSWOi/sTmRPfvpTY1DJ nJgg== X-Gm-Message-State: AAQBX9eFAzPwsvC7dohkgCiFMluAuPkKM9YBTI+pera13QmPV2nHEmKX I9MnCRkPSUeBcBCsgKGZTMGPTpRY08s= X-Google-Smtp-Source: AKy350aVwzEFnsZAJemNZy+Zcy6UwRhsnDigTFzGHb8W/up8rCXqEPDBBuYS/HPbJy/Lm3n1EOZiNA== X-Received: by 2002:a0d:ea4e:0:b0:541:8a02:c42b with SMTP id t75-20020a0dea4e000000b005418a02c42bmr673219ywe.28.1681357264149; Wed, 12 Apr 2023 20:41:04 -0700 (PDT) Received: from nostalgia-for-inf-0.lan ([204.111.132.134]) by smtp.gmail.com with ESMTPSA id d139-20020a814f91000000b0054f8de7c6f1sm181146ywb.70.2023.04.12.20.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 20:41:03 -0700 (PDT) From: Andrew Patterson Date: Wed, 12 Apr 2023 23:40:59 -0400 Message-Id: <20230413034059.5585-1-andrewpatt7@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1130; envelope-from=andrewpatt7@gmail.com; helo=mail-yw1-x1130.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-fontconfig-config-file): Add support for adding arbitrary SXML configuration into fonts.conf; * doc/guix.texi (Fonts Services): Update the documentation. --- One of the main reasons I haven't started using guix home is that I use fonts.conf for setting default fonts, which guix home doesn't work with. This patch fixes that issue, by letting you add arbitrary XML to fonts.conf via SXML. doc/guix.texi | 16 +++++++++----- gnu/home/services/fontutils.scm | 38 ++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 13 deletions(-) base-commit: 60c97c60a53686ec321eb541b85e01b6decc2014 diff --git a/doc/guix.texi b/doc/guix.texi index acb6f0c2e1..f1cfdd77f4 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -42968,8 +42968,10 @@ library is used by many applications to access fonts on the system. @defvar home-fontconfig-service-type This is the service type for generating configurations for Fontconfig. -Its associated value is a list of strings (or gexps) pointing to fonts -locations. +Its associated value is a list of either strings (or gexps) pointing to +fonts locations, or SXML (@pxref{SXML,,, guile, GNU Guile Reference +Manual}) fragments to be converted into XML and put inside the main +@code{fontconfig} node. Generally, it is better to extend this service than to directly configure it, as its default value is the default Guix Home's profile @@ -42977,13 +42979,17 @@ font installation path (@file{~/.guix-home/profile/share/fonts}). If you configure this service directly, be sure to include the above directory. -A typical extension for adding an additional font directory might look -like this: +A typical extension for adding an additional font directory and setting +a font as the default monospace font might look like this: @lisp (simple-service 'additional-fonts-service home-fontconfig-service-type - (list "~/.nix-profile/share/fonts")) + (list "~/.nix-profile/share/fonts" + '(alias + (family "monospace") + (prefer + (family "Liberation Mono"))))) @end lisp @end defvar diff --git a/gnu/home/services/fontutils.scm b/gnu/home/services/fontutils.scm index 3399cb7ec8..0e60bc2035 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 Andrew Patterson ;;; ;;; This file is part of GNU Guix. ;;; @@ -23,6 +24,8 @@ (define-module (gnu home services fontutils) #:use-module (gnu packages fontutils) #:use-module (guix gexp) #:use-module (srfi srfi-1) + #:use-module (ice-9 match) + #:use-module (sxml simple) #:export (home-fontconfig-service-type)) @@ -35,17 +38,36 @@ (define-module (gnu home services fontutils) ;;; ;;; Code: -(define (add-fontconfig-config-file directories) +(define (write-fontconfig-doctype) + "Prints fontconfig's DOCTYPE to current-output-port." + ;; This is necessary because SXML doesn't seem to have a way to represent a doctype, + ;; but sxml->xml /does/ currently call any thunks in the SXML with the XML output port + ;; as current-output-port, allowing the output to include arbitrary text instead of + ;; just properly quoted XML. + (format #t "")) + +(define (config->sxml config) + "Converts a record into the SXML representation +of fontconfig's fonts.conf file." + (define (snippets->sxml snippet) + (match snippet + ((or (? string? dir) + (? gexp? dir)) + `(dir ,dir)) + ((? list?) + snippet))) + `(*TOP* (*PI* xml "version='1.0'") + ,write-fontconfig-doctype + (fontconfig + ,@(map snippets->sxml config)))) + +(define (add-fontconfig-config-file config) `(("fontconfig/fonts.conf" ,(mixed-text-file "fonts.conf" - (apply string-append - `(" - -\n" ,@(map (lambda (directory) - (string-append " " directory "\n")) - directories) - "\n")))))) + (call-with-output-string + (lambda (port) + (sxml->xml (config->sxml config) port))))))) (define (regenerate-font-cache-gexp _) `(("profile/share/fonts"