From c175588099632c474f988fb4a61ab51ad2523975 Mon Sep 17 00:00:00 2001 From: Emmanuel Rosa Date: Sun, 17 Nov 2019 12:05:41 +0700 Subject: DateZone: get timezone series from TZDIR The DateZone plugin calls `getTimeZoneSeriesFromOlsonFile` using the hard-coded path /usr/share/zoneinfo. While that may work just fine on most Linux distros, it does not work on NixOS since that directory is always locates somewhere under /nix/store. Based on mild research, it seems the environment variable TZDIR is commonly set to the absolute path to `zoneinfo` (but without a trailing slash). This change modifies the DateZone plugin to first try getting the zoneinfo path from the TZDIR environment variable, falling back to the hard-coded path /usr/share/zoneinfo --- src/Xmobar/Plugins/DateZone.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Xmobar/Plugins/DateZone.hs b/src/Xmobar/Plugins/DateZone.hs index 22be6c2..35767a8 100644 --- a/src/Xmobar/Plugins/DateZone.hs +++ b/src/Xmobar/Plugins/DateZone.hs @@ -28,6 +28,9 @@ import Xmobar.Run.Exec import Control.Concurrent.STM import System.IO.Unsafe +import System.Environment (lookupEnv) + +import Data.Maybe (fromMaybe) import Data.Time.Format import Data.Time.LocalTime @@ -63,7 +66,8 @@ instance Exec DateZone where locale <- getTimeLocale atomically $ putTMVar localeLock lock if z /= "" then do - timeZone <- getTimeZoneSeriesFromOlsonFile ("/usr/share/zoneinfo/" ++ z) + tzdir <- lookupEnv "TZDIR" + timeZone <- getTimeZoneSeriesFromOlsonFile ((fromMaybe "/usr/share/zoneinfo" tzdir) ++ "/" ++ z) go (dateZone f locale timeZone) else go (date f locale) -- cgit v1.2.3