projects/guix·blob python-team · refs

90 lines · 3.4 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 Andrew Tropin <[email protected]>
3;;; Copyright © 2021 Xinglu Chen <[email protected]>
4;;; Copyright © 2023 Giacomo Leidi <[email protected]>
5;;; Copyright © 2023 Andrew Patterson <[email protected]>
6;;;
7;;; This file is part of GNU Guix.
8;;;
9;;; GNU Guix is free software; you can redistribute it and/or modify it
10;;; under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation; either version 3 of the License, or (at
12;;; your option) any later version.
13;;;
14;;; GNU Guix is distributed in the hope that it will be useful, but
15;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22;;; Commentary:
23;;;
24;;; Services related to fonts. home-fontconfig service provides
25;;; fontconfig configuration, which allows fc-* utilities to find
26;;; fonts in Guix Home's profile and regenerates font cache on
27;;; activation.
28;;;
29;;; Code:
30
31(define-module (gnu home services fontutils)
32 #:use-module (gnu home services)
33 #:use-module (gnu packages fontutils)
34 #:use-module (guix gexp)
35 #:use-module (srfi srfi-1)
36 #:use-module (ice-9 match)
37 #:use-module (sxml simple)
38
39 #:export (home-fontconfig-service-type))
40
41(define (write-fontconfig-doctype)
42 "Prints fontconfig's DOCTYPE to current-output-port."
43 ;; This is necessary because SXML doesn't seem to have a way to represent a doctype,
44 ;; but sxml->xml /does/ currently call any thunks in the SXML with the XML output port
45 ;; as current-output-port, allowing the output to include arbitrary text instead of
46 ;; just properly quoted XML.
47 (format #t "<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>"))
48
49(define (config->sxml config)
50 "Converts a <home-fontconfig-configuration> record into the SXML representation
51of fontconfig's fonts.conf file."
52 (define (snippets->sxml snippet)
53 (match snippet
54 ((or (? string? dir)
55 (? gexp? dir))
56 `(dir ,dir))
57 ((? list?)
58 snippet)))
59 `(*TOP* (*PI* xml "version='1.0'")
60 ,write-fontconfig-doctype
61 (fontconfig
62 ,@(map snippets->sxml config))))
63
64(define (add-fontconfig-config-file config)
65 `(("fontconfig/fonts.conf"
66 ,(mixed-text-file
67 "fonts.conf"
68 (call-with-output-string
69 (lambda (port)
70 (sxml->xml (config->sxml config) port)))))))
71
72(define (regenerate-font-cache-gexp _)
73 `(("profile/share/fonts"
74 ,#~(system* #$(file-append fontconfig "/bin/fc-cache") "-fv"))))
75
76(define home-fontconfig-service-type
77 (service-type (name 'home-fontconfig)
78 (extensions
79 (list (service-extension
80 home-xdg-configuration-files-service-type
81 add-fontconfig-config-file)
82 (service-extension
83 home-run-on-change-service-type
84 regenerate-font-cache-gexp)))
85 (compose concatenate)
86 (extend append)
87 (default-value '("~/.guix-home/profile/share/fonts"))
88 (description
89 "Provides configuration file for fontconfig and make
90fc-* utilities aware of font packages installed in Guix Home's profile.")))