From e1ce1009156d7923bcf1b93ca3918c9b18123007 Mon Sep 17 00:00:00 2001 From: Simon Streit Date: Mon, 8 Aug 2022 16:56:43 +0200 Subject: services: Add wsdd service. * doc/guix.texi: Add documentation for wsdd service. * gnu/services/samba.scm (): New record. (wsdd-service-type): New variable. (wsdd-shepherd-services): New procedure. * gnu/tests/samba.scm (%wsdd-os): Add variable. (run-wsdd-test): New procedure. (%test-wsdd): New variable. Signed-off-by: Lars-Dominik Braun --- gnu/services/samba.scm | 106 ++++++++++++++++++++++++++++++++++++++++++++++++- gnu/tests/samba.scm | 59 ++++++++++++++++++++++++++- 2 files changed, 163 insertions(+), 2 deletions(-) (limited to 'gnu') diff --git a/gnu/services/samba.scm b/gnu/services/samba.scm index 2c9e52a0b0..4e930d61dc 100644 --- a/gnu/services/samba.scm +++ b/gnu/services/samba.scm @@ -41,7 +41,10 @@ #:export (samba-service-type samba-configuration - samba-smb-conf)) + samba-smb-conf + + wsdd-service-type + wsdd-configuration)) (define %smb-conf (plain-file "smb.conf" "[global] @@ -180,3 +183,104 @@ controller or as a regular domain member.") (service-extension profile-service-type (compose list samba-configuration-package)))) (default-value (samba-configuration)))) + + +;;; +;;; WSDD +;;; + +(define-record-type* + wsdd-configuration + make-wsdd-configuration + wsdd-configuration? + (package wsdd-configuration-package + (default wsdd)) + (ipv4only? wsdd-configuration-ipv4only? + (default #f)) + (ipv6only? wsdd-configuration-ipv6only? + (default #f)) + (chroot wsdd-configuration-chroot + (default #f)) + (hop-limit wsdd-configuration-hop-limit + (default 1)) + (interfaces wsdd-configuration-interfaces + (default '())) + (uuid-device wsdd-configuration-uuid-device + (default #f)) + (domain wsdd-configuration-domain + (default #f)) + (host-name wsdd-configuration-host-name + (default #f)) + (preserve-case? wsdd-configuration-preserve-case? + (default #f)) + (workgroup wsdd-configuration-workgroup + (default "WORKGROUP"))) + +(define wsdd-accounts + (list + (user-group (name "wsdd")) + (user-account (name "wsdd") + (group "wsdd") + (comment "Web Service Discovery user") + (home-directory "/var/empty") + (shell (file-append shadow "/sbin/nologin"))))) + +(define (wsdd-shepherd-service config) + (match-record config + (package ipv4only? ipv6only? chroot hop-limit interfaces uuid-device + domain host-name preserve-case? workgroup) + (list (shepherd-service + (documentation "The Web Service Discovery daemon enables (Samba) hosts, +like your local NAS device, to be found by Web Service Discovery Clients +like Windows.") + (provision '(wsdd)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/bin/wsdd") + #$@(if ipv4only? + #~("--ipv4only") + '()) + #$@(if ipv6only? + #~("--ipv6only") + '()) + #$@(if chroot + #~("--chroot" #$chroot) + '()) + #$@(if hop-limit + #~("--hoplimit" #$(number->string hop-limit)) + '()) + #$@(map (lambda (interfaces) + (string-append "--interface=" interfaces)) + interfaces) + #$@(if uuid-device + #~("--uuid" #$uuid-device) + '()) + #$@(if domain + #~("--domain" #$domain) + '()) + #$@(if host-name + #~("--hostname" #$host-name) + '()) + #$@(if preserve-case? + #~("--preserve-case") + '()) + #$@(if workgroup + #~("--workgroup" #$workgroup) + '())) + #:user "wsdd" + #:group "wsdd" + #:log-file "/var/log/wsdd.log")) + (stop #~(make-kill-destructor)))))) + +(define wsdd-service-type + (service-type + (name 'wsdd) + (description "Web Service Discovery Daemon") + (extensions + (list (service-extension shepherd-root-service-type + wsdd-shepherd-service) + (service-extension account-service-type + (const wsdd-accounts)) + (service-extension profile-service-type + (compose list wsdd-configuration-package)))) + (default-value (wsdd-configuration)))) diff --git a/gnu/tests/samba.scm b/gnu/tests/samba.scm index 27d7ea49c3..cb2762a90e 100644 --- a/gnu/tests/samba.scm +++ b/gnu/tests/samba.scm @@ -26,7 +26,8 @@ #:use-module (gnu packages samba) #:use-module (guix gexp) #:use-module (guix store) - #:export (%test-samba)) + #:export (%test-samba + %test-wsdd)) ;;; @@ -156,3 +157,59 @@ (name "samba") (description "Connect to a running Samba daemon.") (value (run-samba-test)))) + + +;;; +;;; The wsdd service. +;;; + +(define %wsdd-os + (let ((base-os (simple-operating-system + (service dhcp-client-service-type) + (service wsdd-service-type)))) + (operating-system + (inherit base-os) + (packages (cons wsdd (operating-system-packages base-os)))))) + +(define* (run-wsdd-test) + "Return a test of an OS running wsdd service." + + (define vm + (virtual-machine + (operating-system (marionette-operating-system + %wsdd-os + #:imported-modules '((gnu services herd)))) + (port-forwardings '((3702 . 3702) + (5357 . 5357))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-26) + (srfi srfi-64)) + + (define marionette + (make-marionette '(#$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "wsdd") + + ;; Here shall be more tests to begin with. + + (test-assert "wsdd running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'wsdd)) + marionette)) + + (test-end)))) + + (gexp->derivation "wsdd-test" test)) + +(define %test-wsdd + (system-test + (name "wsdd") + (description "Connect to a running wsdd daemon.") + (value (run-wsdd-test)))) -- cgit v1.2.3