From 23527b87e86dbbf92c37718dc449d8ad0a8d3758 Mon Sep 17 00:00:00 2001
From: nixo <nicolo@nixo.xyz>
Date: Tue, 27 Oct 2020 14:18:23 +0100
Subject: [PATCH 2/2] gnu: Add kristall.

* gnu/packages/web-browsers.scm (kristall): New variable.
---
 gnu/packages/web-browsers.scm | 99 +++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)

diff --git a/gnu/packages/web-browsers.scm b/gnu/packages/web-browsers.scm
index eb49a8fdea..30bc9ca9cf 100644
--- a/gnu/packages/web-browsers.scm
+++ b/gnu/packages/web-browsers.scm
@@ -46,6 +46,7 @@
   #:use-module (gnu packages documentation)
   #:use-module (gnu packages fltk)
   #:use-module (gnu packages fontutils)
+  #:use-module (gnu packages fonts)
   #:use-module (gnu packages freedesktop)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages glib)
@@ -60,6 +61,7 @@
   #:use-module (gnu packages lisp)
   #:use-module (gnu packages lisp-xyz)
   #:use-module (gnu packages lua)
+  #:use-module (gnu packages markup)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
@@ -341,6 +343,103 @@ access.")
     (properties `((lint-hidden-cve . ("CVE-2016-9179"))))
     (license license:gpl2)))
 
+(define-public kristall
+  ;; Fixes to the build system applied after the latest tag
+  ;; Use tagged release when updating
+  (let ((commit "b684f94f1af9a19c1a6fd70d72097a13b75e1ca6")
+        (revision "1"))
+    (package
+      (name "kristall")
+      (version (string-append "0.3-" revision "." (string-take commit 7)))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/MasterQ32/kristall")
+               (commit "bf5b2ecd0fde117d550adeadee48d74034ed2cdb")))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32
+           "1zakhxr30n7dawig7c8mizaqxwnqn3a7pz0yi7hc55nn7n7iyr6l"))
+         (modules '((guix build utils)))
+         (snippet
+          '(begin
+             ;; Remove bundled programs.
+             (with-directory-excursion "lib"
+               ;; Delete extra (bundled) files
+               (map (lambda (dir) (delete-file-recursively dir))
+                    ;; "BreezeStyleSheets"
+                    '("cmark")))
+             ;; Contains executable of 7z and pscp
+             (delete-file-recursively "ci/tools")
+             ;; Remove bundled fonts
+             (delete-file-recursively "src/fonts")
+             #t))))
+      (build-system gnu-build-system)
+      (arguments
+       `(#:modules ((guix build gnu-build-system)
+                    (guix build qt-utils)
+                    (guix build utils))
+         #:imported-modules (,@%gnu-build-system-modules
+                             (guix build qt-utils))
+         #:make-flags
+         (list (string-append "PREFIX=" %output))
+         #:phases
+         (modify-phases %standard-phases
+           (delete 'configure)          ; no ./configure script
+           (delete 'check)              ; no check target
+           (add-before 'build 'set-program-version
+             ;; runs git describe --tags by default
+             (lambda _
+               ;; configure.ac relies on ‘git --describe’ to get the version.
+               ;; Patch it to just return the real version number directly.
+               (substitute* "src/kristall.pro"
+                 (("(KRISTALL_VERSION=).*" _ match)
+                  (string-append match ,version "\n")))))
+           (add-before 'build 'replace-bundled-cmark
+             (lambda _
+               (substitute* "src/kristall.pro"
+                 (("(^include\\(.*cmark.*)" _ match)
+                  (string-append
+                   "LIBS += -I" (assoc-ref %build-inputs "cmark") " -lcmark")))
+               (substitute* "src/renderers/markdownrenderer.cpp"
+                 (("(include.*node.*)" _ match)
+                  (string-append "// " match)))))
+           (add-before 'build 'replace-bundled-fonts
+             (lambda _
+               (let ((noto (assoc-ref %build-inputs "font-google-noto"))
+                     (openmoji (assoc-ref %build-inputs "font-openmoji"))
+                     (srcdir "/share/fonts/truetype/")
+                     (outdir "src/fonts/"))
+                 (mkdir-p outdir)
+                 (copy-file
+                  (string-append noto srcdir "NotoColorEmoji.ttf")
+                  (string-append outdir "NotoColorEmoji.ttf"))
+                 (copy-file
+                  (string-append openmoji srcdir "OpenMoji-Color.ttf")
+                  (string-append outdir "OpenMoji-Color.ttf")))
+               #t))
+           (add-after 'install 'wrap-program
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let ((out (assoc-ref outputs "out")))
+                 (wrap-qt-program out "kristall"))
+               #t)))))
+      (inputs
+       `(("cmark" ,cmark)
+         ("font-google-noto" ,font-google-noto)
+         ("font-openmoji" ,font-openmoji)
+         ("openssl" ,openssl)
+         ("qtbase" ,qtbase)
+         ("qtmultimedia" ,qtmultimedia)
+         ("qtsvg" ,qtsvg)))
+      (home-page "https://github.com/MasterQ32/kristall")
+      (synopsis "Small-internet graphical client")
+      (description "Graphical small-internet client with with many features
+including multi-protocol support (gemini, http, https, gopher, finger),
+bookmarks, TSL certificates management, outline generation, tabbed interface
+and more.")
+      (license license:gpl3))))
+
 (define-public qutebrowser
   (package
     (name "qutebrowser")
-- 
2.28.0

