From a03943ec0024f22e2b7d6358dea9989c9eb06499 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 19 Apr 2020 18:01:13 +0200 Subject: services: Add 'hostapd-service-type'. * gnu/services/networking.scm (): New record type. (hostapd-configuration-file, hostapd-shepherd-services): New procedures. (hostapd-service-type): New variable. * doc/guix.texi (Networking Services): Document it. --- gnu/services/networking.scm | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'gnu/services') diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 618dd95969..30e1173f2b 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -32,6 +32,7 @@ (define-module (gnu services networking) #:use-module (gnu services) #:use-module (gnu services base) + #:use-module (gnu services configuration) #:use-module (gnu services shepherd) #:use-module (gnu services dbus) #:use-module (gnu system shadow) @@ -140,6 +141,16 @@ wpa-supplicant-configuration-extra-options wpa-supplicant-service-type + hostapd-configuration + hostapd-configuration? + hostapd-configuration-package + hostapd-configuration-interface + hostapd-configuration-ssid + hostapd-configuration-broadcast-ssid? + hostapd-configuration-channel + hostapd-configuration-driver + hostapd-service-type + openvswitch-service-type openvswitch-configuration @@ -1358,6 +1369,66 @@ whatever the thing is supposed to do)."))) implements authentication, key negotiation and more for wireless networks.") (default-value (wpa-supplicant-configuration))))) + +;;; +;;; Hostapd. +;;; + +(define-record-type* + hostapd-configuration make-hostapd-configuration + hostapd-configuration? + (package hostapd-configuration-package + (default hostapd)) + (interface hostapd-configuration-interface ;string + (default "wlan0")) + (ssid hostapd-configuration-ssid) ;string + (broadcast-ssid? hostapd-configuration-broadcast-ssid? ;Boolean + (default #t)) + (channel hostapd-configuration-channel ;integer + (default 1)) + (driver hostapd-configuration-driver ;string + (default "nl80211")) + ;; See for a list of + ;; additional options we could add. + (extra-settings hostapd-configuration-extra-settings ;string + (default ""))) + +(define (hostapd-configuration-file config) + "Return the configuration file for CONFIG, a ." + (match-record config + (interface ssid broadcast-ssid? channel driver extra-settings) + (plain-file "hostapd.conf" + (string-append "\ +# Generated from your Guix configuration. + +interface=" interface " +ssid=" ssid " +ignore_broadcast_ssid=" (if broadcast-ssid? "0" "1") " +channel=" (number->string channel) "\n" +extra-settings "\n")))) + +(define* (hostapd-shepherd-services config #:key (requirement '())) + "Return Shepherd services for hostapd." + (list (shepherd-service + (provision '(hostapd)) + (requirement `(user-processes ,@requirement)) + (documentation "Run the hostapd WiFi access point daemon.") + (start #~(make-forkexec-constructor + (list #$(file-append hostapd "/sbin/hostapd") + #$(hostapd-configuration-file config)) + #:log-file "/var/log/hostapd.log")) + (stop #~(make-kill-destructor))))) + +(define hostapd-service-type + (service-type + (name 'hostapd) + (extensions + (list (service-extension shepherd-root-service-type + hostapd-shepherd-services))) + (description + "Run the @uref{https://w1.fi/hostapd/, hostapd} daemon for Wi-Fi access +points and authentication servers."))) + ;;; ;;; Open vSwitch -- cgit v1.2.3 From 5e7076f2a54e84894b5d8f3ef719e7a552b5bb03 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 19 Apr 2020 22:06:32 +0200 Subject: services: Add 'simulated-wifi-service-type'. * gnu/services/networking.scm (simulated-wifi-shepherd-services): New procedure. (simulated-wifi-service-type): New variable. * doc/guix.texi (Networking Services): Document it. --- doc/guix.texi | 11 +++++++++++ gnu/services/networking.scm | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) (limited to 'gnu/services') diff --git a/doc/guix.texi b/doc/guix.texi index 3e6746b59d..d2cd11576f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13684,6 +13684,17 @@ configuration file reference. @end table @end deftp +@defvr {Scheme Variable} simulated-wifi-service-type +This is the type of a service to simulate WiFi networking, which can be +useful in virtual machines for testing purposes. The service loads the +Linux kernel +@uref{https://www.kernel.org/doc/html/latest/networking/mac80211_hwsim/mac80211_hwsim.html, +@code{mac80211_hwsim} module} and starts hostapd to create a pseudo WiFi +network that can be seen on @code{wlan0}, by default. + +The service's value is a @code{hostapd-configuration} record. +@end defvr + @cindex iptables @defvr {Scheme Variable} iptables-service-type This is the service type to set up an iptables configuration. iptables is a diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 30e1173f2b..383b2b0d04 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -151,6 +151,8 @@ hostapd-configuration-driver hostapd-service-type + simulated-wifi-service-type + openvswitch-service-type openvswitch-configuration @@ -1429,6 +1431,52 @@ extra-settings "\n")))) "Run the @uref{https://w1.fi/hostapd/, hostapd} daemon for Wi-Fi access points and authentication servers."))) +(define (simulated-wifi-shepherd-services config) + "Return Shepherd services to run hostapd with CONFIG, a +, as well as services to set up WiFi hardware +simulation." + (append (hostapd-shepherd-services config + #:requirement + '(unblocked-wifi + mac-simulation-module)) + (list (shepherd-service + (provision '(unblocked-wifi)) + (requirement '(file-systems mac-simulation-module)) + (documentation + "Unblock WiFi devices for use by mac80211_hwsim.") + (start #~(lambda _ + (invoke #$(file-append util-linux "/sbin/rfkill") + "unblock" "0") + (invoke #$(file-append util-linux "/sbin/rfkill") + "unblock" "1"))) + (one-shot? #t)) + (shepherd-service + (provision '(mac-simulation-module)) + (requirement '(file-systems)) + (modules '((guix build utils))) + (documentation + "Load the mac80211_hwsim Linux kernel module.") + (start (with-imported-modules '((guix build utils)) + #~(lambda _ + ;; XXX: We can't use 'load-linux-module*' here because it + ;; expects a flat module directory. + (setenv "LINUX_MODULE_DIRECTORY" + "/run/booted-system/kernel/lib/modules") + (invoke #$(file-append kmod "/bin/modprobe") + "mac80211_hwsim")))) + (one-shot? #t))))) + +(define simulated-wifi-service-type + (service-type + (name 'simulated-wifi) + (extensions + (list (service-extension shepherd-root-service-type + simulated-wifi-shepherd-services))) + (default-value (hostapd-configuration + (interface "wlan1") + (ssid "Test Network"))) + (description "Run hostapd to simulate WiFi connectivity."))) + ;;; ;;; Open vSwitch -- cgit v1.2.3 From 7d903d2ff7e17406c0650541f35e37a99dab8759 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 20 Apr 2020 19:36:41 +0200 Subject: services: Don't use the deprecated 'make-forkexec-constructor' call. Passing 'make-forkexec-constructor' a string or several string arguments has been deprecated since dmd 0.1. * gnu/services/base.scm (rngd-service-type): In 'start' method, pass a list as the first argument to 'make-forkexec-constructor'. * gnu/services/desktop.scm (bluetooth-shepherd-service): Likewise. * gnu/services/spice.scm (spice-vdagent-shepherd-service): Likewise. --- gnu/services/base.scm | 2 +- gnu/services/desktop.scm | 4 ++-- gnu/services/spice.scm | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'gnu/services') diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 094bc5297e..d7f3c30b7b 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -557,7 +557,7 @@ down."))) (documentation "Add TRNG to entropy pool.") (requirement '(udev)) (provision '(trng)) - (start #~(make-forkexec-constructor #$@rngd-command)) + (start #~(make-forkexec-constructor '#$rngd-command)) (stop #~(make-kill-destructor)))))) (define* (rngd-service #:key diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm index 8663243256..e165d87c5f 100644 --- a/gnu/services/desktop.scm +++ b/gnu/services/desktop.scm @@ -452,8 +452,8 @@ site} for more information." (requirement '(dbus-system udev)) (documentation "Run the bluetoothd daemon.") (start #~(make-forkexec-constructor - (string-append #$(bluetooth-configuration-bluez config) - "/libexec/bluetooth/bluetoothd"))) + (list #$(file-append (bluetooth-configuration-bluez config) + "/libexec/bluetooth/bluetoothd")))) (stop #~(make-kill-destructor)))) (define bluetooth-service-type diff --git a/gnu/services/spice.scm b/gnu/services/spice.scm index 8a835fe78e..fd85dc234f 100644 --- a/gnu/services/spice.scm +++ b/gnu/services/spice.scm @@ -54,7 +54,7 @@ (documentation "Spice vdagentd service") (requirement '(udev)) (provision '(spice-vdagentd)) - (start #~(make-forkexec-constructor #$@spice-vdagentd-command)) + (start #~(make-forkexec-constructor '#$spice-vdagentd-command)) (stop #~(make-kill-destructor))))) (define spice-vdagent-profile -- cgit v1.2.3 From b25ecfa2e0ab6642dc35f7f68a24117e33f5795f Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 20 Apr 2020 22:30:09 +0200 Subject: services: dovecot: 'stop' method returns #f upon success. * gnu/services/mail.scm (dovecot-shepherd-service)[stop]: Use 'invoke' instead of 'make-forkexec-constructor'. Previously, the 'stop' method would return the PID of the "dovecot stop" process, which would be interpreted as a failure to stop the service. --- gnu/services/mail.scm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gnu/services') diff --git a/gnu/services/mail.scm b/gnu/services/mail.scm index 7791780dfc..cfcaf4601b 100644 --- a/gnu/services/mail.scm +++ b/gnu/services/mail.scm @@ -1544,9 +1544,10 @@ greyed out, instead of only later giving \"not selectable\" popup error. (start #~(make-forkexec-constructor (list (string-append #$dovecot "/sbin/dovecot") "-F"))) - (stop #~(make-forkexec-constructor - (list (string-append #$dovecot "/sbin/dovecot") - "stop"))))))) + (stop #~(lambda _ + (invoke #$(file-append dovecot "/sbin/dovecot") + "stop") + #f)))))) (define %dovecot-pam-services (list (unix-pam-service "dovecot"))) -- cgit v1.2.3 From e3358a831e7d5d9e8dc614340e49ea5aeb11a7ff Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 21 Apr 2020 16:06:53 +0200 Subject: gnu: shepherd: Update to 0.8.0. * gnu/packages/admin.scm (shepherd): Update to 0.8.0. * gnu/services/shepherd.scm (shepherd-configuration-file): Use 'default-pid-file-timeout' instead of fiddling with '%pid-file-timeout'. --- gnu/packages/admin.scm | 4 ++-- gnu/services/shepherd.scm | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'gnu/services') diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm index bf5aa9d890..c55a319d04 100644 --- a/gnu/packages/admin.scm +++ b/gnu/packages/admin.scm @@ -199,14 +199,14 @@ and provides a \"top-like\" mode (monitoring).") (define-public shepherd (package (name "shepherd") - (version "0.7.0") + (version "0.8.0") (source (origin (method url-fetch) (uri (string-append "mirror://gnu/shepherd/shepherd-" version ".tar.gz")) (sha256 (base32 - "07j3vd0y8zab2nwbrwj0ahrfif1ldm5sjssn7m3dw4s307fsrfzx")))) + "02lbc8z5gd8v8wfi4yh1zww8mk03w0zcwnmk4l4p3vpjlvlb63ll")))) (build-system gnu-build-system) (arguments '(#:configure-flags '("--localstatedir=/var"))) diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index e99458da43..2f30c6c907 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm @@ -297,8 +297,7 @@ and return the resulting '.go' file." ;; everything slow. Thus, increase the timeout compared to the ;; default 5s in the Shepherd 0.7.0. See ;; . - ;; XXX: Use something better when the next Shepherd is out. - (set! (@@ (shepherd service) %pid-file-timeout) 30) + (default-pid-file-timeout 30) ;; Arrange to spawn a REPL if something goes wrong. This is better ;; than a kernel panic. -- cgit v1.2.3 From 2b0c0d9301aa70ce57055073a813a3a02c4f1eed Mon Sep 17 00:00:00 2001 From: Brice Waegeneire Date: Sun, 5 Apr 2020 21:51:41 +0200 Subject: services: Add udev-rules-service helper. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * doc/guix.texi (Base services): Add documentation for 'udev-rules-service'. Replace examples of 'udev-service-type' extension with 'udev-rules-service'. * gnu/services/base.scm (udev-rules-service): New procedure. Signed-off-by: Ludovic Courtès --- doc/guix.texi | 46 +++++++++++++++++++++++----------------------- gnu/services/base.scm | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 23 deletions(-) (limited to 'gnu/services') diff --git a/doc/guix.texi b/doc/guix.texi index 990703c4a8..538797a7a3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12850,8 +12850,12 @@ A directory path where the @command{guix-daemon} will perform builds. @deffn {Scheme Procedure} udev-service [#:udev @var{eudev} #:rules @code{'()}] Run @var{udev}, which populates the @file{/dev} directory dynamically. udev rules can be provided as a list of files through the @var{rules} -variable. The procedures @code{udev-rule} and @code{file->udev-rule} from -@code{(gnu services base)} simplify the creation of such rule files. +variable. The procedures @code{udev-rule}, @code{udev-rules-service} +and @code{file->udev-rule} from @code{(gnu services base)} simplify the +creation of such rule files. + +The @command{herd rules udev} command, as root, returns the name of the +directory containing all the active udev rules. @end deffn @deffn {Scheme Procedure} udev-rule [@var{file-name} @var{contents}] @@ -12870,23 +12874,27 @@ upon detecting a USB device with a given product identifier. "ATTR@{product@}==\"Example\", " "RUN+=\"/path/to/script\""))) @end lisp - -The @command{herd rules udev} command, as root, returns the name of the -directory containing all the active udev rules. @end deffn -Here we show how the default @var{udev-service} can be extended with it. +@deffn {Scheme Procedure} udev-rules-service [@var{name} @var{rules}] @ + [#:groups @var{groups}] +Return a service that extends @code{udev-service-type } with @var{rules} +and @code{account-service-type} with @var{groups} as system groups. +This works by creating a singleton service type +@var{name}@code{-udev-rules}, of which the returned service is an +instance. + +Here we show how it can be used to extend @var{udev-service} with the +previously defined rule @code{%example-udev-rule}. @lisp (operating-system ;; @dots{} (services - (modify-services %desktop-services - (udev-service-type config => - (udev-configuration (inherit config) - (rules (append (udev-configuration-rules config) - (list %example-udev-rule)))))))) + (cons* (udev-rules-service 'usb-thing %example-udev-rule) + %desktop-services))) @end lisp +@end deffn @deffn {Scheme Procedure} file->udev-rule [@var{file-name} @var{file}] Return a udev file named @var{file-name} containing the rules defined @@ -12926,7 +12934,7 @@ without root privileges. It also details how to create the the rules defined within the @var{android-udev-rules} package. To create such a group, we must define it both as part of the @var{supplementary-groups} of our @var{user-account} declaration, as -well as in the @var{groups} field of the @var{operating-system} record. +well as in the @var{groups} of the @var{udev-rules-service} procedure. @lisp (use-modules (gnu packages android) ;for android-udev-rules @@ -12940,19 +12948,11 @@ well as in the @var{groups} field of the @var{operating-system} record. (supplementary-groups '("adbusers" ;for adb "wheel" "netdev" "audio" "video"))))) - - (groups (cons (user-group (system? #t) (name "adbusers")) - %base-groups)) - ;; @dots{} - (services - (modify-services %desktop-services - (udev-service-type - config => - (udev-configuration (inherit config) - (rules (cons android-udev-rules - (udev-configuration-rules config)))))))) + (cons (udev-rules-service 'android android-udev-rules + #:groups '("adbusers")) + %desktop-services))) @end lisp @defvr {Scheme Variable} urandom-seed-service-type diff --git a/gnu/services/base.scm b/gnu/services/base.scm index d7f3c30b7b..2913478e4a 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -12,6 +12,7 @@ ;;; Copyright © 2019 John Soo ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2020 Florian Pelz +;;; Copyright © 2020 Brice Waegeneire ;;; ;;; This file is part of GNU Guix. ;;; @@ -92,6 +93,7 @@ udev-service udev-rule file->udev-rule + udev-rules-service login-configuration login-configuration? @@ -2042,6 +2044,26 @@ extra rules from the packages listed in @var{rules}." (service udev-service-type (udev-configuration (udev udev) (rules rules)))) +(define* (udev-rules-service name rules #:key (groups '())) + "Return a service that extends udev-service-type with RULES and +account-service-type with GROUPS as system groups. This works by creating a +singleton service type NAME-udev-rules, of which the returned service is an +instance." + (let* ((name (symbol-append name '-udev-rules)) + (account-extension + (const (map (lambda (group) + (user-group (name group) (system? #t))) + groups))) + (udev-extension (const (list rules))) + (type (service-type + (name name) + (extensions (list + (service-extension + account-service-type account-extension) + (service-extension + udev-service-type udev-extension)))))) + (service type #f))) + (define swap-service-type (shepherd-service-type 'swap -- cgit v1.2.3