summary refs log tree commit diff
path: root/pkgs/development/libraries/qt-6/patches/0004-qtbase-fix-locating-tzdir-on-NixOS.patch
blob: 5ccc9346d6d9c7c0000b50ea9ff2d5c597487904 (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From b1533ac42718835499ec633ffb3b1bed0d040719 Mon Sep 17 00:00:00 2001
From: Nick Cao <nickcao@nichi.co>
Date: Fri, 14 Apr 2023 09:35:25 +0800
Subject: [PATCH 04/11] qtbase: fix locating tzdir on NixOS

---
 src/corelib/time/qtimezoneprivate_tz.cpp | 27 +++++++++++++++---------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp
index e702a5d6b43..2ac88c1cd10 100644
--- a/src/corelib/time/qtimezoneprivate_tz.cpp
+++ b/src/corelib/time/qtimezoneprivate_tz.cpp
@@ -56,7 +56,11 @@ static bool isTzFile(const QString &name);
 // zone1970.tab).
 static QTzTimeZoneHash loadTzTimeZones()
 {
-    QString path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
+    // Try TZDIR first, in case we're running on NixOS.
+    QString path = QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/zone.tab");
+    // Fallback to traditional paths in case we are not on NixOS.
+    if (!QFile::exists(path))
+        path = QStringLiteral("/usr/share/zoneinfo/zone.tab");
     if (!QFile::exists(path))
         path = QStringLiteral("/usr/lib/zoneinfo/zone.tab");
 
@@ -773,18 +777,21 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::findEntry(const QByteArray &ianaId)
         if (!tzif.open(QIODevice::ReadOnly))
             return ret;
     } else {
-        // Open named tz, try modern path first, if fails try legacy path
-        tzif.setFileName("/usr/share/zoneinfo/"_L1 + QString::fromLocal8Bit(ianaId));
+        // Try TZDIR first, in case we're running on NixOS
+        tzif.setFileName(QFile::decodeName(qgetenv("TZDIR")) + QStringLiteral("/") + QString::fromLocal8Bit(ianaId));
         if (!tzif.open(QIODevice::ReadOnly)) {
-            tzif.setFileName("/usr/lib/zoneinfo/"_L1 + QString::fromLocal8Bit(ianaId));
+            tzif.setFileName(QLatin1String("/usr/share/zoneinfo/") + QString::fromLocal8Bit(ianaId));
             if (!tzif.open(QIODevice::ReadOnly)) {
-                // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
-                auto check = validatePosixRule(ianaId);
-                if (check.isValid) {
-                    ret.m_hasDst = check.hasDst;
-                    ret.m_posixRule = ianaId;
+                tzif.setFileName("/usr/lib/zoneinfo/"_L1 + QString::fromLocal8Bit(ianaId));
+                if (!tzif.open(QIODevice::ReadOnly)) {
+                    // ianaId may be a POSIX rule, taken from $TZ or /etc/TZ
+                    auto check = validatePosixRule(ianaId);
+                    if (check.isValid) {
+                        ret.m_hasDst = check.hasDst;
+                        ret.m_posixRule = ianaId;
+                    }
+                    return ret;
                 }
-                return ret;
             }
         }
     }
-- 
2.42.0