| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 |
|
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 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 | |
| 44 | |
| 45 | |
| 46 | |
| 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
|
| 51 | of 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
|
| 90 | fc-* utilities aware of font packages installed in Guix Home's profile.")))
|