summaryrefslogtreecommitdiff
path: root/tw
diff options
context:
space:
mode:
authorTimo Wilken2023-05-09 20:20:50 -0400
committerTimo Wilken2023-05-15 23:40:55 +0200
commit937fc746ea4c5d3e7d20f40b0c6ee74daabd14b5 (patch)
tree268b143a94dfc12204e0d6a07c83b6635259dab9 /tw
parent2526efc2e38663e9b096e7e5a095e34b929034f0 (diff)
Add script to set timezone from the network
Diffstat (limited to 'tw')
-rw-r--r--tw/system/lap.scm28
1 files changed, 27 insertions, 1 deletions
diff --git a/tw/system/lap.scm b/tw/system/lap.scm
index 9a1b8571..307cf590 100644
--- a/tw/system/lap.scm
+++ b/tw/system/lap.scm
@@ -21,7 +21,7 @@
#:use-module (tw system))
(use-package-modules android certs cups disk docker file-systems gnome
- kerberos linux mtools pulseaudio search shells wm xorg)
+ kerberos linux mtools pulseaudio search shells tls wm xorg)
(use-service-modules admin authentication avahi base cups dbus desktop docker
kerberos linux mcron networking pm syncthing vpn xorg)
@@ -100,6 +100,29 @@ EndSection
)
"))
+(define set-timezone-script
+ ;; Every time we connect to a network, get our timezone from network geolocation.
+ ;; https://wiki.archlinux.org/title/System_time
+ (with-extensions (list guile-gnutls) ; needed by (web client)
+ #~(begin
+ (use-modules (srfi srfi-11) ; `let-values'
+ (web client)
+ (web response))
+ (define tz-api-url "https://ipapi.co/timezone")
+ (define /etc/localtime "/etc/localtime")
+ ;; According to the Arch Wiki, when checking for "up" as the second
+ ;; argument, VPN connections could cause undesired timezone changes.
+ (when (and (string=? "connectivity-change" (caddr (command-line)))
+ (string=? "FULL" (getenv "CONNECTIVITY_STATE")))
+ (let-values (((response timezone) (http-get tz-api-url)))
+ (unless (= 200 (response-code response))
+ (error "Got error response to request:" response))
+ (let ((zonefile (string-append #$tzdata "/share/zoneinfo/" timezone)))
+ (delete-file /etc/localtime)
+ (symlink zonefile /etc/localtime)
+ (format (current-error-port)
+ "Successfully updated timezone to ~a" timezone)))))))
+
;; TODO: Nouveau claims (in dmesg) that I have a NVIDIA GM204. Maybe
;; only use (select-firmware "^nvidia/gm204/"). linux-firmware only
;; has a gr/ subdir for that, and acr/ symlinked from gm200. No pmu/
@@ -380,6 +403,9 @@ support extra features (acr, pmu, gr).")
(extra-special-file "/etc/guix/channels.scm"
(scheme-file "channels.scm" system-channels))
+ (extra-special-file "/etc/NetworkManager/dispatcher.d/09-set-timezone"
+ (program-file "set-timezone" set-timezone-script))
+
(modify-services %desktop-services
(gdm-service-type
config =>