Subject: [bug#63006] [PATCH 1/3] gnu: libical: Find the time zone database in the environment.

From: Leo Famulari <[email-masked]>
Date: Fri, 21 Apr 2023 17:01:00 -0400

* gnu/packages/patches/libical-respect-tzdir.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/calendar.scm (libical)[source]: Use it.
[inputs]: Remove tzdata.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/calendar.scm                     |  3 +-
 .../patches/libical-respect-tzdir.patch       | 38 +++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/libical-respect-tzdir.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index b631fa6d5a..f301c33cfa 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1393,6 +1393,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/libffi-3.3-powerpc-fixes.patch		\
   %D%/packages/patches/libffi-float128-powerpc64le.patch	\
   %D%/packages/patches/libgeotiff-fix-tests-with-proj-9.1.1.patch	\
+  %D%/packages/patches/libical-respect-tzdir.patch		\
   %D%/packages/patches/libobjc2-unbundle-robin-map.patch	\
   %D%/packages/patches/librime-fix-build-with-gcc10.patch	\
   %D%/packages/patches/libvirt-add-install-prefix.patch	\
diff --git a/gnu/packages/calendar.scm b/gnu/packages/calendar.scm
index cf4286100d..030f9c52e7 100644
--- a/gnu/packages/calendar.scm
+++ b/gnu/packages/calendar.scm
@@ -127,6 +127,7 @@ (define-public libical
               (uri (string-append
                     "https://github.com/libical/libical/releases/download/v"
                     version "/libical-" version ".tar.gz"))
+              (patches (search-patches "libical-respect-tzdir.patch"))
               (sha256
                (base32
                 "0cqc1wpalxmxjx8dmcaga9w8kd5l7944hqmidz43hifaf7fhaixl"))))
@@ -166,7 +167,7 @@ (define-public libical
            pkg-config
            vala))
     (inputs
-     (list glib libxml2 tzdata))
+     (list glib libxml2))
     (propagated-inputs
      ;; In Requires.private of libical.pc.
      (list icu4c))
diff --git a/gnu/packages/patches/libical-respect-tzdir.patch b/gnu/packages/patches/libical-respect-tzdir.patch
new file mode 100644
index 0000000000..f749addf44
--- /dev/null
+++ b/gnu/packages/patches/libical-respect-tzdir.patch
@@ -0,0 +1,38 @@
+Copied from Nix:
+
+https://github.com/NixOS/nixpkgs/blob/0336bd874374a9e33947ace8a289e5c785e44a19/pkgs/development/libraries/libical/respect-env-tzdir.patch
+
+This functionality will be available in libical 3.1.0, whenever that is
+released:
+
+https://github.com/libical/libical/issues/350
+
+--- a/src/libical/icaltz-util.c
++++ b/src/libical/icaltz-util.c
+@@ -94,9 +94,9 @@
+ static const char *zdir = NULL;
+ 
+ static const char *search_paths[] = {
++    "/etc/zoneinfo",
+     "/usr/share/zoneinfo",
+     "/usr/lib/zoneinfo",
+-    "/etc/zoneinfo",
+     "/usr/share/lib/zoneinfo"
+ };
+ 
+@@ -178,6 +178,15 @@
+     const char *fname = ZONES_TAB_SYSTEM_FILENAME;
+     size_t i, num_search_paths;
+ 
++   const char *env_tzdir = getenv ("TZDIR");
++   if (env_tzdir) {
++       sprintf (file_path, "%s/%s", env_tzdir, fname);
++       if (!access (file_path, F_OK|R_OK)) {
++           zdir = env_tzdir;
++           return;
++       }
++   }
++
+     num_search_paths = sizeof(search_paths) / sizeof(search_paths[0]);
+     for (i = 0; i < num_search_paths; i++) {
+         snprintf(file_path, MAXPATHLEN, "%s/%s", search_paths[i], fname);
-- 
2.39.2