aboutsummaryrefslogtreecommitdiff
path: root/tw/system/lap.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tw/system/lap.scm')
-rw-r--r--tw/system/lap.scm31
1 files changed, 22 insertions, 9 deletions
diff --git a/tw/system/lap.scm b/tw/system/lap.scm
index 2a9a10ed..516de321 100644
--- a/tw/system/lap.scm
+++ b/tw/system/lap.scm
@@ -24,7 +24,7 @@
#:use-module (tw services wireguard)
#:use-module (tw system))
-(use-package-modules android certs cups disk docker file-systems gnome
+(use-package-modules android certs cups disk docker file-systems gnome guile
kerberos linux mtools pulseaudio search shells tls wm xorg)
(use-service-modules admin authentication avahi base cups dbus desktop docker
@@ -85,24 +85,37 @@ 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)
+ ;; https://wiki.archlinux.org/title/Network_configuration/Wireless#Respecting_the_regulatory_domain
+ (with-extensions (list guile-json-4 guile-gnutls) ; guile-gnutls needed by (web client)
#~(begin
- (use-modules (srfi srfi-11) ; `let-values'
+ (use-modules ((srfi srfi-11) #:select (let-values))
+ (json)
(web client)
(web response))
- (define tz-api-url "https://ipapi.co/timezone")
+ (define api-url "https://ipapi.co/json")
;; 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)))
+ (let-values (((response text) (http-get api-url)))
(unless (= 200 (response-code response))
(error "Got error response to request:" response))
- (let ((zonefile (string-append #$tzdata "/share/zoneinfo/" timezone)))
+ (let* ((json (json-string->scm text))
+ (timezone (assoc-ref json "timezone"))
+ (zonefile (string-append #$tzdata "/share/zoneinfo/" timezone))
+ (regdb-country (assoc-ref json "country_code"))
+ (error-code
+ (status:exit-val
+ ;; Set WiFi regulatory domain to use the correct channels.
+ (system* #$(file-append iw "/bin/iw") "reg" "set" regdb-country))))
+ (format (current-error-port) "Updated WiFi regdomain to ~a: ~a~%"
+ regdb-country (if (zero? error-code) "success"
+ (format #f "error ~d" error-code)))
+ ;; Set local timezone.
(delete-file "/etc/localtime")
- (symlink zonefile "/etc/localtime"))
- (format (current-error-port)
- "Successfully updated timezone to ~a~%" timezone))))))
+ (symlink zonefile "/etc/localtime")
+ (format (current-error-port)
+ "Updated timezone to ~a: success~%" timezone)))))))
(define-public %lap-system
(operating-system