Hilton Chain <[email protected]> writes:
>> 1. Too many configuration fields. e.g. bluetooth-configuration
>> I don't think all the fields have at least one user. :) I remember the
>> experience of trying to find ‘auto-enable?’ from the documentation.
>> Keeping
>> track of upstream updates would be a pain, and it requires knowledge to
>> write
>> readable documentation for some fields.
>>
>> If it's a port of the original configuration, why not supply an INI file
>> directly? (extra-config)
>>
>> If the point is to use Scheme, why not use an alist and serialize it to
>> INI?
>> (RDE, free-style configurations)
> Instead of alist, I tried to use the current configuration interface,
> but with service extensions exposed. I'll see how to add serializers in
> later and experiment with more services.
Here's one example for serializers (the INI serializer is taken from RDE).
Configuration interface:
--8<---------------cut here---------------start------------->8---
(service iwd-service-type
(iwd-configuration
(network-configuration? #f)
(control-port-over-nl80211? #f)
(address-randomization 'network)))
--8<---------------cut here---------------end--------------->8---
--8<---------------cut here---------------start------------->8---
(service iwd-service-type
(iwd-configuration
(config
'((General
((EnableNetworkConfiguration . #f)
(ControlPortOverNL80211 . #f)
(AddressRandomization . network)))))))
--8<---------------cut here---------------end--------------->8---
--8<---------------cut here---------------start------------->8---
(service iwd-service-type
(iwd-configuration
(config (plain-file "iwd.conf" "\
[General]
EnableNetworkConfiguration = false
ControlPortOverNL80211 = false
AddressRandomization = network
"))))
--8<---------------cut here---------------end--------------->8---
Service definition
--8<---------------cut here---------------start------------->8---
(define-record-type* <iwd-configuration>
iwd-configuration make-iwd-configuration
iwd-configuration?
this-iwd-configuration
(iwd iwd-configuration-iwd
(default iwd))
(network-configuration? iwd-configuration-network-configuration?
(default #f))
(control-port-over-nl80211? iwd-configuration-control-port-over-nl80211?
(default #t))
(address-randomization iwd-configuration-address-randomization
(default #f))
(log-file iwd-configuration-log-file
(default "/var/log/iwd.log"))
(config iwd-configuration-config
(default #f))
;; Serializers.
(serialized-config iwd-configuration-serialized-config
(default (%iwd-serialized-config
this-iwd-configuration))
(thunked))
;; Extensions.
(shepherd iwd-configuration-shepherd
(default (%iwd-shepherd
this-iwd-configuration))
(thunked))
(dbus iwd-configuration-dbus
(default (%iwd-dbus
this-iwd-configuration))
(thunked))
(etc iwd-configuration-etc
(default (%iwd-etc
this-iwd-configuration))
(thunked))
(profile iwd-configuration-profile
(default (%iwd-profile
this-iwd-configuration))
(thunked))
(log-rotation iwd-configuration-log-rotation
(default (%iwd-log-rotation
this-iwd-configuration))
(thunked)))
(define %iwd-serialized-config
(match-record-lambda <iwd-configuration>
(config
network-configuration? control-port-over-nl80211? address-randomization)
(match config
(#f
(let ((ini-config
`((General
((EnableNetworkConfiguration . ,network-configuration?)
(ControlPortOverNL80211 . ,control-port-over-nl80211?)
(AddressRandomization . ,address-randomization))))))
(mixed-text-file
"iwd.conf"
#~(string-append #$@(ini-serialize ini-config)))))
((? file-like?)
config)
((? alist?)
(mixed-text-file
"iwd.conf"
#~(string-append #$@(ini-serialize config))))
(_
(leave (G_ "unsupported config: ~a~%") config)))))
(define %iwd-shepherd
(match-record-lambda <iwd-configuration>
(iwd
network-configuration?
log-file)
(list (shepherd-service
(documentation "Run iwd")
(provision `(,@(if network-configuration?
'(networking)
'())
iwd))
(requirement '(user-processes dbus-system))
(start
#~(make-forkexec-constructor
(list (string-append #$iwd "/libexec/iwd"))
#:log-file #$log-file))
(stop
#~(make-kill-destructor))
(actions
(list (shepherd-configuration-action "/etc/iwd/main.conf")))))))
(define %iwd-dbus
(compose list iwd-configuration-iwd))
(define %iwd-etc
(match-record-lambda <iwd-configuration>
(serialized-config)
`(("iwd/main.conf" ,serialized-config))))
(define %iwd-profile
(compose list iwd-configuration-iwd))
(define %iwd-log-rotation
(compose list iwd-configuration-log-file))
(define iwd-service-type
(service-type
(name 'iwd)
(extensions
(list (service-extension shepherd-root-service-type
iwd-configuration-shepherd)
(service-extension dbus-root-service-type
iwd-configuration-dbus)
(service-extension etc-service-type
iwd-configuration-etc)
(service-extension profile-service-type
iwd-configuration-profile)
(service-extension log-rotation-service-type
iwd-configuration-log-rotation)))
(default-value (iwd-configuration))
(description "")))
--8<---------------cut here---------------end--------------->8---