Subject: Re: Minetest can't retrieve packages for additional content due to SSL certificate either invalid or not available

From: Maxime Devos <[email-masked]>
Date: Sat, 22 Jan 2022 15:20:01 +0100

Hi,

I can confirm in a pure environment:

1. guix shell --pure minetest le-certs -- minetest
2. click on the +
3. In the GUI: ‘No packages could be retrieved’.
   In the terminal:

   2022-01-22 13:19:05: ERROR[Main]:
https://content.minetest.net/api/packages/?type=mod&type=game&type=txp&protocol_version=39&engine_version=5.4.1&hide=nonfree&hide=desktop_default
not found (SSL peer certificate or SSH remote key was not OK) (response
code 0)

Minetest uses curl HTTPS, so as a fix, I tried adding

    (native-search-paths
     (package-native-search-paths curl))

to the package definition of minetest, such that SSL_CERT_FILE/DIR
would be set.

To test:

1. apply the patch (see attachement)
2. ./pre-guix shell --pure minetest le-certs -- minetest
3. click on the +
4. In the GUI, a list of downloadable mods is shown.

The first patch contains the actual fix, the later patches do some
‘cleaning’.  I'll sent a mail later confirming that the later patches
don't break Minetest (assuming that's actually the case).

Greetings,
Maxime.
From d4f83265f4638b69bb62338159ff251d61889e9d Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sat, 22 Jan 2022 13:24:22 +0000
Subject: [PATCH 1/3] gnu: minetest: Find TLS certificates.

* gnu/packages/minetest.scm (minetest)[native-search-paths]: Add curl's search paths.

Fixes: <https://issues.guix.gnu.org/4031>.

Reported-by: pkill9 <[email-masked]>
---
 gnu/packages/minetest.scm | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/gnu/packages/minetest.scm b/gnu/packages/minetest.scm
index c431942473..c6762bb1f2 100644
--- a/gnu/packages/minetest.scm
+++ b/gnu/packages/minetest.scm
@@ -7,7 +7,7 @@
 ;;; Copyright © 2019–2021 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2021 Trevor Hass <[email-masked]>
 ;;; Copyright © 2020, 2021 Liliana Marie Prikler <[email-masked]>
-;;; Copyright © 2021 Maxime Devos <[email-masked]>
+;;; Copyright © 2021, 2022 Maxime Devos <[email-masked]>
 ;;; This file is part of GNU Guix.
 ;;;
 ;;; GNU Guix is free software; you can redistribute it and/or modify it
@@ -109,12 +109,16 @@ (define-public minetest
                (setenv "HOME" "/tmp")
                (invoke "src/minetest" "--run-unittests")))))))
     (native-search-paths
-     (list (search-path-specification
-            (variable "MINETEST_SUBGAME_PATH")
-            (files '("share/minetest/games")))
-           (search-path-specification
-            (variable "MINETEST_MOD_PATH")
-            (files '("share/minetest/mods")))))
+     (append (list (search-path-specification
+                    (variable "MINETEST_SUBGAME_PATH")
+                    (files '("share/minetest/games")))
+                   (search-path-specification
+                    (variable "MINETEST_MOD_PATH")
+                    (files '("share/minetest/mods"))))
+         ;; Make sure that Minetest can find TLS certificates such that
+         ;; built-in mod downloader/installer can work.  See
+         ;; <https://issues.guix.gnu.org/40319>.
+         (package-native-search-paths curl)))
     (native-inputs
      (list pkg-config))
     (inputs

base-commit: 1bd250783d7118c3101dd2a6e090f3d6904b24a0
prerequisite-patch-id: 8e682d35d35a9e0268c00cc009fa5b394d7adc94
prerequisite-patch-id: 7a183c58627b7225154f72a76a1c241c5b6cd419
prerequisite-patch-id: ae89e00772cf3737e32b3b7bd191bfbeaaf5d0ed
prerequisite-patch-id: 0c52e17c64d9c6a43374c31557f2f529d7179052
prerequisite-patch-id: cbb90155003134235f98b750f5e4de2096c9e414
prerequisite-patch-id: ff8b567c0b58018b9c2085a324ce02711eadc77e
prerequisite-patch-id: 6383c3c10d0c47bf13ee87560633d6ec8c89e7df
prerequisite-patch-id: eeb5c4446896b7d5209de79e7b9a2486a9a5dadb
prerequisite-patch-id: 2aa957d39e26f32c6c69cd2dfe0ceb75e6a78d14
-- 
2.34.0

From 8ee40a95a6ce6eb654306c0a482ed78dcf1aad21 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sat, 22 Jan 2022 13:40:44 +0000
Subject: [PATCH 2/3] gnu: minetest: Remove input labels.

Converting the phases from a S-exp to a G-exp is strictly speaking not
necessary, but it seemed nice for consistency with #:configure-flags.
Likewise for the origin snippet.

* gnu/packages/minetest.scm (minetest)[arguments]: Remove labels.
  (minetest)[source]{snippet}: Remove trailing #t and convert to G-exp.
---
 gnu/packages/minetest.scm | 73 +++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 38 deletions(-)

diff --git a/gnu/packages/minetest.scm b/gnu/packages/minetest.scm
index c6762bb1f2..c3ca443395 100644
--- a/gnu/packages/minetest.scm
+++ b/gnu/packages/minetest.scm
@@ -42,6 +42,7 @@ (define-module (gnu packages minetest)
   #:use-module (gnu packages xorg)
   #:use-module (guix packages)
   #:use-module (guix git-download)
+  #:use-module (guix gexp)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system copy)
   #:use-module (guix build-system trivial)
@@ -66,48 +67,44 @@ (define-public minetest
                (search-patches
                 "minetest-add-MINETEST_MOD_PATH.patch"))
               (snippet
-               '(begin
-                  ;; Delete bundled libraries.
-                  (delete-file-recursively "lib")
-                  #t))))
+               ;; Delete bundled libraries.
+               #~(delete-file-recursively "lib"))))
     (build-system cmake-build-system)
     (arguments
      `(#:configure-flags
-       (list "-DRUN_IN_PLACE=0"
-             "-DENABLE_FREETYPE=1"
-             "-DENABLE_GETTEXT=1"
-             "-DENABLE_SYSTEM_JSONCPP=TRUE"
-             (string-append "-DIRRLICHT_INCLUDE_DIR="
-                            (assoc-ref %build-inputs "irrlicht")
-                            "/include/irrlicht")
-             (string-append "-DCURL_INCLUDE_DIR="
-                            (assoc-ref %build-inputs "curl")
-                            "/include/curl"))
+       ,#~(let ((irrlicht #$(lookup-package-input this-package "irrlicht"))
+                (curl #$(lookup-package-input this-package "curl")))
+            (list "-DRUN_IN_PLACE=0"
+                  "-DENABLE_FREETYPE=1"
+                  "-DENABLE_GETTEXT=1"
+                  "-DENABLE_SYSTEM_JSONCPP=TRUE"
+                  (string-append "-DIRRLICHT_INCLUDE_DIR=" irrlicht
+                                 "/include/irrlicht")
+                  (string-append "-DCURL_INCLUDE_DIR=" curl "/include/curl")))
        #:phases
-       (modify-phases %standard-phases
-         (add-after 'unpack 'patch-sources
-           (lambda* (#:key inputs #:allow-other-keys)
-             (substitute* "src/filesys.cpp"
-               ;; Use store-path for "rm" instead of non-existing FHS path.
-               (("\"/bin/rm\"")
-                (string-append "\"" (assoc-ref inputs "coreutils") "/bin/rm\"")))
-             (substitute* "src/CMakeLists.txt"
-               ;; Let minetest binary remain in build directory.
-               (("set\\(EXECUTABLE_OUTPUT_PATH .*\\)") ""))
-             (substitute* "src/unittest/test_servermodmanager.cpp"
-               ;; do no override MINETEST_SUBGAME_PATH
-               (("(un)?setenv\\(\"MINETEST_SUBGAME_PATH\".*\\);")
-                "(void)0;"))
-             (setenv "MINETEST_SUBGAME_PATH"
-                     (string-append (getcwd) "/games")) ; for check
-             #t))
-         (replace 'check
-           (lambda* (#:key tests? #:allow-other-keys)
-             ;; Thanks to our substitutions, the tests should also run
-             ;; when invoked on the target outside of `guix build'.
-             (when tests?
-               (setenv "HOME" "/tmp")
-               (invoke "src/minetest" "--run-unittests")))))))
+       ,#~(modify-phases %standard-phases
+            (add-after 'unpack 'patch-sources
+              (lambda* (#:key inputs #:allow-other-keys)
+                (substitute* "src/filesys.cpp"
+                  ;; Use store-path for "rm" instead of non-existing FHS path.
+                  (("\"/bin/rm\"")
+                   (string-append "\"" (search-input-file inputs "bin/rm") "\"")))
+                (substitute* "src/CMakeLists.txt"
+                  ;; Let minetest binary remain in build directory.
+                  (("set\\(EXECUTABLE_OUTPUT_PATH .*\\)") ""))
+                (substitute* "src/unittest/test_servermodmanager.cpp"
+                  ;; do no override MINETEST_SUBGAME_PATH
+                  (("(un)?setenv\\(\"MINETEST_SUBGAME_PATH\".*\\);")
+                   "(void)0;"))
+                (setenv "MINETEST_SUBGAME_PATH"
+                        (string-append (getcwd) "/games")))) ; for check
+            (replace 'check
+              (lambda* (#:key tests? #:allow-other-keys)
+                ;; Thanks to our substitutions, the tests should also run
+                ;; when invoked on the target outside of `guix build'.
+                (when tests?
+                  (setenv "HOME" "/tmp")
+                  (invoke "src/minetest" "--run-unittests")))))))
     (native-search-paths
      (append (list (search-path-specification
                     (variable "MINETEST_SUBGAME_PATH")
-- 
2.34.0

From f543ece46f0195b6a44493ed6253e4891669baee Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sat, 22 Jan 2022 13:52:46 +0000
Subject: [PATCH 3/3] gnu: minetest-data: Switch to 'copy-build-system'.

This makes the package definition much simpler.

* gnu/packages/minetest.scm (minetest-data)[native-inputs]{source}: Remove.
[build-system]: Switch to 'copy-build-system'.
[arguments]<#:modules>: Remove.
[arguments]<#:builder>: Replace by an equivalent #:install-plan.
---
 gnu/packages/minetest.scm | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/minetest.scm b/gnu/packages/minetest.scm
index c3ca443395..b5ba19c951 100644
--- a/gnu/packages/minetest.scm
+++ b/gnu/packages/minetest.scm
@@ -161,21 +161,9 @@ (define minetest-data
               (sha256
                (base32
                 "0i45lbnikvgj9kxdp0yphpjjwjcgp4ibn49xkj78j5ic1s9n8jd4"))))
-    (build-system trivial-build-system)
-    (native-inputs
-     `(("source" ,source)))
+    (build-system copy-build-system)
     (arguments
-     `(#:modules ((guix build utils))
-       #:builder (begin
-                   (use-modules (guix build utils))
-                   (let ((install-dir (string-append
-                                       %output
-                                       "/share/minetest/games/minetest_game")))
-                     (mkdir-p install-dir)
-                     (copy-recursively
-                      (assoc-ref %build-inputs "source")
-                      install-dir)
-                     #t))))
+     (list #:install-plan #~'(("." "share/minetest/games/minetest_game"))))
     (synopsis "Main game data for the Minetest game engine")
     (description
      "Game data for the Minetest infinite-world block sandbox game.")
-- 
2.34.0