From 937fc746ea4c5d3e7d20f40b0c6ee74daabd14b5 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Tue, 9 May 2023 20:20:50 -0400 Subject: Add script to set timezone from the network --- tw/system/lap.scm | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tw/system/lap.scm') 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 => -- cgit v1.2.3