summaryrefslogtreecommitdiff
path: root/gnu/services/networking.scm
diff options
context:
space:
mode:
authorSergey Trofimov <sarg@sarg.org.ru>2025-05-22 13:07:54 +0200
committerLudovic Courtès <ludo@gnu.org>2025-06-05 22:43:36 +0200
commitc4e1081f82c4f45e34cf6aca1e3f3347dd384c79 (patch)
tree7b822896beb6768b8360645298824ff3a3f4abf5 /gnu/services/networking.scm
parente4995c9978017886f0ae85609edda90072cfc2d9 (diff)
services: networking: Add iwd-service-type.
* gnu/services/networking.scm (iwd-service-type): New service type. (iwd-configuration), (iwd-settings), (iwd-scan-settings), (iwd-general-settings), (iwd-network-settings): New configuration types. * doc/guix.texi (Networking setup): Document it. Change-Id: I852115b9c6768b3ec4eedb34a7f9e66438bd1429 Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/services/networking.scm')
-rw-r--r--gnu/services/networking.scm249
1 files changed, 249 insertions, 0 deletions
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 4279c77b2d7..0d6c524877b 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -41,6 +41,7 @@
41;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. 41;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
42 42
43(define-module (gnu services networking) 43(define-module (gnu services networking)
44 #:use-module (gnu home services utils)
44 #:use-module (gnu services) 45 #:use-module (gnu services)
45 #:use-module (gnu services base) 46 #:use-module (gnu services base)
46 #:use-module (gnu services configuration) 47 #:use-module (gnu services configuration)
@@ -56,6 +57,7 @@
56 #:use-module (gnu packages bash) 57 #:use-module (gnu packages bash)
57 #:use-module (gnu packages cluster) 58 #:use-module (gnu packages cluster)
58 #:use-module (gnu packages connman) 59 #:use-module (gnu packages connman)
60 #:use-module (gnu packages dns)
59 #:use-module (gnu packages freedesktop) 61 #:use-module (gnu packages freedesktop)
60 #:use-module (gnu packages linux) 62 #:use-module (gnu packages linux)
61 #:use-module (gnu packages tor) 63 #:use-module (gnu packages tor)
@@ -80,6 +82,7 @@
80 #:use-module (srfi srfi-9) 82 #:use-module (srfi srfi-9)
81 #:use-module (srfi srfi-26) 83 #:use-module (srfi srfi-26)
82 #:use-module (srfi srfi-43) 84 #:use-module (srfi srfi-43)
85 #:use-module ((ice-9 curried-definitions) #:select (define))
83 #:use-module (ice-9 format) 86 #:use-module (ice-9 format)
84 #:use-module (ice-9 match) 87 #:use-module (ice-9 match)
85 #:use-module (ice-9 string-fun) 88 #:use-module (ice-9 string-fun)
@@ -236,6 +239,21 @@
236 wpa-supplicant-configuration-extra-options 239 wpa-supplicant-configuration-extra-options
237 wpa-supplicant-service-type 240 wpa-supplicant-service-type
238 241
242 iwd-configuration
243 iwd-configuration-config
244 iwd-configuration-ignored-interfaces
245 iwd-configuration-ignored-phys
246 iwd-configuration-interfaces
247 iwd-configuration-iwd
248 iwd-configuration-phys
249 iwd-configuration-shepherd-provision
250 iwd-configuration-shepherd-requirement
251 iwd-service-type
252 iwd-general-settings
253 iwd-network-settings
254 iwd-scan-settings
255 iwd-settings
256
239 hostapd-configuration 257 hostapd-configuration
240 hostapd-configuration? 258 hostapd-configuration?
241 hostapd-configuration-package 259 hostapd-configuration-package
@@ -2103,6 +2121,237 @@ implements authentication, key negotiation and more for wireless networks.")
2103 2121
2104 2122
2105;;; 2123;;;
2124;;; IWD
2125;;;
2126(define (iwd-uglify-field-name name)
2127 (object->camel-case-string name 'upper))
2128
2129(define (iwd-serialize-base field-name val)
2130 (format #f "~a=~a\n" field-name val))
2131
2132(define (iwd-serialize-field field-name val)
2133 (iwd-serialize-base (iwd-uglify-field-name field-name) val))
2134
2135(define iwd-serialize-number iwd-serialize-field)
2136
2137(define (iwd-serialize-boolean field-name value)
2138 (iwd-serialize-field
2139 (string-trim-right (symbol->string field-name) #\?)
2140 (if value "true" "false")))
2141
2142(define (iwd-serialize-alist field-name value)
2143 (if (null? value)
2144 ""
2145 #~(string-append #$@(generic-serialize-alist list
2146 iwd-serialize-base
2147 value))))
2148
2149(define-enumerated-field-type resolving-service
2150 (none systemd resolvconf)
2151 (prefix iwd-))
2152
2153(define-configuration iwd-general-settings
2154 (enable-network-configuration?
2155 (boolean #f)
2156 "Setting this option to true enables @code{iwd} to configure the network
2157interfaces with the IP addresses.")
2158 (extra-options
2159 (alist '())
2160 "An association list of option symbols/strings to string values to be
2161appended to the General settings group.")
2162
2163 (prefix iwd-))
2164
2165(define-configuration iwd-network-settings
2166 (enable-ipv6?
2167 (boolean #t)
2168 "Sets the global default that tells @code{iwd} whether it should configure
2169IPv6 addresses and routes")
2170
2171 (name-resolving-service
2172 (resolving-service 'none)
2173 "Configures a DNS resolution method used by the system.")
2174
2175 (extra-options
2176 (alist '())
2177 "An association list of option symbols/strings to string values to be
2178appended to the Network settings group.")
2179
2180 (prefix iwd-))
2181
2182(define-configuration iwd-scan-settings
2183 (disable-periodic-scan?
2184 (boolean #f)
2185 "Setting this option to @code{#t} will prevent @code{iwd} from issuing the
2186periodic scans for the available networks while disconnected.")
2187
2188 (initial-periodic-scan-interval
2189 (number 10)
2190 "The initial periodic scan interval upon disconnect (in seconds).")
2191
2192 (maximum-periodic-scan-interval
2193 (number 300)
2194 "The maximum periodic scan interval (in seconds).")
2195
2196 (disable-roaming-scan?
2197 (boolean #f)
2198 "Setting this option to @code{#t} will prevent @code{iwd} from trying to scan
2199when roaming decisions are activated.")
2200
2201 (extra-options
2202 (alist '())
2203 "An association list of option symbols/strings to string values to be
2204appended to the Scan settings group.")
2205
2206 (prefix iwd-))
2207
2208(define-maybe iwd-network-settings)
2209(define-maybe iwd-scan-settings)
2210
2211(define ((iwd-serialize-config-section fields) name cfg)
2212 #~(format #f "[~a]\n~a\n"
2213 #$(string-upcase (object->string name) 0 1)
2214 #$(serialize-configuration cfg fields)))
2215
2216(define serialize-iwd-network-settings
2217 (iwd-serialize-config-section iwd-network-settings-fields))
2218
2219(define serialize-iwd-scan-settings
2220 (iwd-serialize-config-section iwd-scan-settings-fields))
2221
2222(define serialize-iwd-general-settings
2223 (iwd-serialize-config-section iwd-general-settings-fields))
2224
2225(define-configuration iwd-settings
2226 (general
2227 (iwd-general-settings (iwd-general-settings))
2228 "General settings.")
2229
2230 (network
2231 maybe-iwd-network-settings
2232 "Network settings.")
2233
2234 (scan
2235 maybe-iwd-scan-settings
2236 "Scan settings.")
2237
2238 (extra-config
2239 (list-of-strings '())
2240 "Extra configuration values to append to the IWD configuration file."
2241 (serializer (lambda (_ value) (string-join value "\n" 'suffix)))))
2242
2243(define-configuration/no-serialization iwd-configuration
2244 (iwd
2245 (file-like iwd)
2246 "The IWD package to use.")
2247
2248 (interfaces
2249 (list-of-strings '())
2250 "If this is set, it must specify @dfn{glob patterns} matching network
2251interfaces that IWD will control.")
2252
2253 (ignored-interfaces
2254 (list-of-strings '())
2255 "If this is set, it must specify @dfn{glob patterns} matching network
2256interfaces that IWD will not manage.")
2257
2258 (phys
2259 (list-of-strings '())
2260 "If this is set, it must specify @dfn{glob patterns} matching network
2261PHYs names that IWD will control.")
2262
2263 (ignored-phys
2264 (list-of-strings '())
2265 "If this is set, it must specify @dfn{glob patterns} matching network
2266PHYs names that IWD will not manage.")
2267
2268 (shepherd-requirement
2269 (list-of-symbols '())
2270 "Shepherd requirements the service should depend on.")
2271
2272 (shepherd-provision
2273 (list-of-symbols '(iwd wireless-daemon))
2274 "The name(s) of the service.")
2275
2276 (config
2277 (iwd-settings (iwd-settings))
2278 "Configuration settings."))
2279
2280(define (iwd-generate-documentation)
2281 (configuration->documentation 'iwd-configuration)
2282 (configuration->documentation 'iwd-settings)
2283 (configuration->documentation 'iwd-general-settings)
2284 (configuration->documentation 'iwd-network-settings)
2285 (configuration->documentation 'iwd-scan-settings))
2286
2287(define (iwd-config-file config)
2288 "Return an IWD configuration file."
2289 (mixed-text-file "main.conf"
2290 (serialize-configuration
2291 (iwd-configuration-config config)
2292 iwd-settings-fields)))
2293
2294(define (iwd-environment config)
2295 (let ((resolver
2296 (and=> (iwd-settings-network (iwd-configuration-config config))
2297 iwd-network-settings-name-resolving-service)))
2298
2299 (if (eq? resolver 'resolvconf)
2300 #~(list (string-append "PATH=" #$openresolv "/sbin"))
2301 '())))
2302
2303(define (iwd-shepherd-service config)
2304 (match-record config <iwd-configuration>
2305 (iwd interfaces ignored-interfaces
2306 phys ignored-phys
2307 shepherd-requirement shepherd-provision)
2308
2309 (list (shepherd-service
2310 (documentation "Run Internet Wireless Daemon")
2311 (provision shepherd-provision)
2312 (requirement `(user-processes dbus-system loopback ,@shepherd-requirement))
2313 (start #~(make-forkexec-constructor
2314 (list (string-append #$iwd "/libexec/iwd")
2315 "--logger=syslog"
2316 #$@(if (null? interfaces) '()
2317 (list (string-append "--interfaces="
2318 (string-join interfaces ","))))
2319 #$@(if (null? ignored-interfaces) '()
2320 (list (string-append "--nointerfaces="
2321 (string-join ignored-interfaces ","))))
2322 #$@(if (null? phys) '()
2323 (list (string-append "--phys="
2324 (string-join phys ","))))
2325 #$@(if (null? ignored-phys) '()
2326 (list (string-append "--nophys="
2327 (string-join ignored-phys ",")))))
2328
2329 #:environment-variables
2330 #$(iwd-environment config)))
2331 (stop #~(make-kill-destructor))))))
2332
2333(define (iwd-etc-service config)
2334 `(("iwd/main.conf" ,(iwd-config-file config))))
2335
2336(define iwd-service-type
2337 (let ((add-iwd-package (compose list iwd-configuration-iwd)))
2338 (service-type (name 'iwd)
2339 (extensions
2340 (list (service-extension shepherd-root-service-type
2341 iwd-shepherd-service)
2342 (service-extension etc-service-type
2343 iwd-etc-service)
2344 (service-extension dbus-root-service-type
2345 add-iwd-package)
2346 (service-extension profile-service-type
2347 add-iwd-package)))
2348 (default-value (iwd-configuration))
2349 (description
2350 "Run @url{https://iwd.wiki.kernel.org/,Iwd},
2351a network connection manager."))))
2352
2353
2354;;;
2106;;; Hostapd. 2355;;; Hostapd.
2107;;; 2356;;;
2108 2357