diff mbox series

[bug#67808,v3,2/3] gnu: Add Nerd Font patching procedure

Message ID f9d5a9688aac069792860f92a642949db1f77204.1702561323.git.saku@laesvuori.fi
State New
Headers show
Series [bug#67808,v3,1/3] gnu: Add nerd-font-patcher | expand

Commit Message

Saku Laesvuori Dec. 14, 2023, 2:01 p.m. UTC
* gnu/packages/fonts.scm (patch-nerd-font): New variable.

Change-Id: Id830424ec68836df7622535207818ff3445c21d4
---
 gnu/packages/fonts.scm | 54 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
diff mbox series

Patch

diff --git a/gnu/packages/fonts.scm b/gnu/packages/fonts.scm
index 813367be8a..3568f38c60 100644
--- a/gnu/packages/fonts.scm
+++ b/gnu/packages/fonts.scm
@@ -59,6 +59,7 @@ 
 ;;; Copyright © 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;; Copyright © 2023 chris <chris@bumblehead.com>
 ;;; Copyright © 2023 Luis Felipe López Acevedo <sirgazil@zoho.com>
+;;; Copyright © 2023 Saku Laesvuori <saku@laesvuori.fi>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -103,6 +104,56 @@  (define-module (gnu packages fonts)
   #:use-module (gnu packages sdl)
   #:use-module (gnu packages xorg))
 
+(define-public (patch-nerd-font font-package)
+  "Return a package that contains the same files as FONT-PACKAGE, except
+that all font files are Nerd Fonts patched."
+  (package
+    (name (string-append (package-name font-package) "-nerd-font"))
+    (version (package-version font-package))
+    (source #f)
+    (build-system trivial-build-system)
+    (arguments
+     (list
+      #:builder
+      (with-imported-modules '((guix build utils))
+        #~(begin
+            (use-modules (guix build utils))
+
+            (define (font-file? filename)
+              ;; The regexp's are from guix/build/font-build-system.scm (install)
+              ;; woff2 is excluded because the fontforge in guix is not compiled
+              ;; with support for it
+              ((file-name-predicate "\\.(tt[fc]|ot[fc]|woff)$")
+               filename #f)) ;the 2. argument is stat but it is unused
+
+            (define (output-path source-path)
+              (let* ((name-version/path (strip-store-file-name source-path))
+                     (path-pieces (string-split name-version/path
+                                                file-name-separator?))
+                     (path-in-package (string-join (cdr path-pieces)
+                                                   file-name-separator-string
+                                                   'prefix)))
+                (string-append #$output (dirname path-in-package))))
+
+            (define (install-and-patch-file file)
+              (if (font-file? file)
+                (invoke (string-append #$(this-package-native-input "nerd-font-patcher")
+                                       "/bin/font-patcher")
+                        file "-o" (output-path file) "--complete")
+                (install-file file (output-path file))))
+
+            (for-each install-and-patch-file
+                      (find-files #$(this-package-native-input
+                                      (package-name font-package))))))))
+    (native-inputs (list nerd-font-patcher font-package))
+    (synopsis
+     (string-append (package-synopsis font-package) " (Nerd Fonts patched)"))
+    (description
+     (string-append (package-description font-package)
+                    " Nerd Fonts patching adds thousands of symbolic glyphs."))
+    (home-page (package-home-page font-package))
+    (license (package-license font-package))))
+
 (define-public font-artifika
   (package
     (name "font-artifika")
@@ -2526,6 +2577,9 @@  (define-public font-jetbrains-mono
 in small sizes, the text looks crisper.")
     (license license:asl2.0)))
 
+(define-public font-jetbrains-mono-nerd-font
+  (patch-nerd-font font-jetbrains-mono))
+
 (define-public font-juliamono
   (package
     (name "font-juliamono")