On a fresh image 99-tollgate-setup ran at activation, before wifi-setup had created /etc/config/wireless, so the open TollGate SSID never appeared (the Pi release image came up with `guix-router`). uci-service- type gains late-defaults, run by wifi-setup after `wifi config` and the first config, then one reboot if any ran. TollGate's setup and the MT6000's 99_zz-wired-private move there. Tested on the Pi (fresh WiFi state: TollGate-C69B after one automatic reboot); MT6000 generation 7 (scripts already done there: no reboot). PITFALLS #57. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4.7 KiB
Scheme
94 lines
4.7 KiB
Scheme
;;; TollGate as a Guix service: its OpenWrt files, run as OpenWrt would.
|
|
(define-module (tollgate-services)
|
|
#:use-module (gnu services)
|
|
#:use-module (guix gexp)
|
|
#:use-module (guix records)
|
|
#:use-module ((gnu packages web) #:select (jq))
|
|
#:use-module (tollgate)
|
|
#:use-module (openwrt-services)
|
|
#:export (tollgate-configuration
|
|
tollgate-configuration?
|
|
tollgate-service-type))
|
|
|
|
;; What TollGate's package does on OpenWrt, mapped onto openwrt-services:
|
|
;; - its procd init script runs as an openwrt-init-script (needs
|
|
;; nodogsplash, which TollGate's setup enables);
|
|
;; - its uci-defaults scripts (portal symlink, 99-tollgate-setup: uhttpd on
|
|
;; :8080, the private network and SSIDs, firewall rules, nodogsplash) run
|
|
;; once, as on first boot -- services come up with the result, which is
|
|
;; what its postinst's restarts achieve;
|
|
;; - /etc/tollgate (config, ecash wallet, portal site) is mutable state,
|
|
;; seeded once; /etc/config/firewall-tollgate is seeded like other UCI
|
|
;; configs; its iface hotplug script restarts it once the WAN is up.
|
|
(define-record-type* <tollgate-configuration>
|
|
tollgate-configuration make-tollgate-configuration
|
|
tollgate-configuration?
|
|
(tollgate tollgate-configuration-tollgate (default tollgate-wrt)))
|
|
|
|
(define (tollgate-file config file)
|
|
(file-append (tollgate-configuration-tollgate config)
|
|
"/share/tollgate-wrt/" file))
|
|
|
|
(define (tollgate-activation config)
|
|
#~(begin
|
|
(use-modules (guix build utils))
|
|
(mkdir-p "/etc/tollgate/ecash")
|
|
(unless (file-exists? "/etc/tollgate/tollgate-captive-portal-site")
|
|
(copy-recursively
|
|
#$(tollgate-file config "tollgate-captive-portal-site")
|
|
"/etc/tollgate/tollgate-captive-portal-site")
|
|
(for-each (lambda (f) (chmod f #o644))
|
|
(find-files "/etc/tollgate/tollgate-captive-portal-site")))))
|
|
|
|
(define tollgate-service-type
|
|
(service-type
|
|
(name 'tollgate)
|
|
(extensions
|
|
(list (service-extension openwrt-init-script-service-type
|
|
(lambda (config)
|
|
(list (openwrt-init-script
|
|
(name "tollgate-wrt")
|
|
(script (tollgate-file
|
|
config "etc/init.d/tollgate-wrt"))
|
|
(requirement
|
|
'(ubus networking nodogsplash))
|
|
(start-priority 95)
|
|
(environment '("TOLLGATE_DEBUG=1"))))))
|
|
(service-extension uci-service-type
|
|
(lambda (config)
|
|
(uci-extension
|
|
(seeds `(("firewall-tollgate"
|
|
,(tollgate-file
|
|
config
|
|
"etc/config/firewall-tollgate"))))
|
|
(defaults
|
|
`(("90-tollgate-captive-portal-symlink"
|
|
,(tollgate-file
|
|
config
|
|
"etc/uci-defaults/90-tollgate-captive-portal-symlink"))))
|
|
;; It configures the radios' APs, so it
|
|
;; must run once /etc/config/wireless
|
|
;; exists.
|
|
(late-defaults
|
|
`(("99-tollgate-setup"
|
|
,(tollgate-file
|
|
config
|
|
"etc/uci-defaults/99-tollgate-setup")))))))
|
|
(service-extension activation-service-type tollgate-activation)
|
|
(service-extension etc-service-type
|
|
(lambda (config)
|
|
`(("hotplug.d/iface/95-tollgate-restart"
|
|
,(tollgate-file
|
|
config
|
|
"etc/hotplug.d/iface/95-tollgate-restart")))))
|
|
;; tollgate, tollgate-wrt and its helper scripts; jq for them.
|
|
(service-extension profile-service-type
|
|
(lambda (config)
|
|
(list (tollgate-configuration-tollgate config)
|
|
jq)))
|
|
;; It needs the captive portal running.
|
|
(service-extension nodogsplash-service-type (const #t))))
|
|
(default-value (tollgate-configuration))
|
|
(description "Run TollGate, which sells network access paid with Cashu
|
|
ecash and announced over Nostr, through the nodogsplash captive portal.")))
|