| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (gnu services avahi)
|
| 20 | #:use-module (gnu services)
|
| 21 | #:use-module (gnu services base)
|
| 22 | #:use-module (gnu services shepherd)
|
| 23 | #:use-module (gnu services dbus)
|
| 24 | #:use-module (gnu system shadow)
|
| 25 | #:use-module (gnu packages admin)
|
| 26 | #:use-module (gnu packages dns)
|
| 27 | #:use-module (guix deprecation)
|
| 28 | #:use-module (guix records)
|
| 29 | #:use-module (guix gexp)
|
| 30 | #:export (avahi-configuration
|
| 31 | avahi-configuration?
|
| 32 |
|
| 33 | avahi-configuration-avahi
|
| 34 | avahi-configuration-debug?
|
| 35 | avahi-configuration-host-name
|
| 36 | avahi-configuration-publish?
|
| 37 | avahi-configuration-publish-workstation?
|
| 38 | avahi-configuration-ipv4?
|
| 39 | avahi-configuration-ipv6?
|
| 40 | avahi-configuration-wide-area?
|
| 41 | avahi-configuration-domains-to-browse
|
| 42 |
|
| 43 | avahi-service-type))
|
| 44 |
|
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 |
|
| 52 | (define-record-type* <avahi-configuration>
|
| 53 | avahi-configuration make-avahi-configuration
|
| 54 | avahi-configuration?
|
| 55 | (avahi avahi-configuration-avahi |
| 56 | (default avahi))
|
| 57 | (debug? avahi-configuration-debug? |
| 58 | (default #f))
|
| 59 | (host-name avahi-configuration-host-name |
| 60 | (default #f))
|
| 61 | (publish? avahi-configuration-publish? |
| 62 | (default #t))
|
| 63 |
|
| 64 | |
| 65 | |
| 66 | (publish-workstation? avahi-configuration-publish-workstation? |
| 67 | (default #t))
|
| 68 |
|
| 69 | (ipv4? avahi-configuration-ipv4? |
| 70 | (default #t))
|
| 71 | (ipv6? avahi-configuration-ipv6? |
| 72 | (default #t))
|
| 73 | (wide-area? avahi-configuration-wide-area? |
| 74 | (default #f))
|
| 75 | (domains-to-browse avahi-configuration-domains-to-browse |
| 76 | (default '())))
|
| 77 |
|
| 78 | (define* (configuration-file config)
|
| 79 | "Return an avahi-daemon configuration file based on CONFIG, an
|
| 80 | <avahi-configuration>."
|
| 81 | (define (bool value)
|
| 82 | (if value "yes\n" "no\n"))
|
| 83 |
|
| 84 | (define host-name (avahi-configuration-host-name config))
|
| 85 |
|
| 86 | (plain-file "avahi-daemon.conf"
|
| 87 | (string-append
|
| 88 | "[server]\n"
|
| 89 | (if host-name
|
| 90 | (string-append "host-name=" host-name "\n")
|
| 91 | "")
|
| 92 |
|
| 93 | "browse-domains=" (string-join
|
| 94 | (avahi-configuration-domains-to-browse
|
| 95 | config))
|
| 96 | "\n"
|
| 97 | "use-ipv4=" (bool (avahi-configuration-ipv4? config))
|
| 98 | "use-ipv6=" (bool (avahi-configuration-ipv6? config))
|
| 99 | "[wide-area]\n"
|
| 100 | "enable-wide-area=" (bool (avahi-configuration-wide-area? config))
|
| 101 | "[publish]\n"
|
| 102 | "disable-publishing="
|
| 103 | (bool (not (avahi-configuration-publish? config)))
|
| 104 | "publish-workstation="
|
| 105 | (bool (avahi-configuration-publish-workstation? config)))))
|
| 106 |
|
| 107 | (define %avahi-accounts
|
| 108 | |
| 109 | (list (user-group (name "avahi") (system? #t))
|
| 110 | (user-account
|
| 111 | (name "avahi")
|
| 112 | (group "avahi")
|
| 113 | (system? #t)
|
| 114 | (comment "Avahi daemon user")
|
| 115 | (home-directory "/var/empty")
|
| 116 | (shell (file-append shadow "/sbin/nologin")))))
|
| 117 |
|
| 118 | (define %avahi-activation
|
| 119 | |
| 120 | #~(begin
|
| 121 | (use-modules (guix build utils))
|
| 122 | (mkdir-p "/run/avahi-daemon")))
|
| 123 |
|
| 124 | (define (avahi-shepherd-service config)
|
| 125 | "Return a list of <shepherd-service> for CONFIG."
|
| 126 | (let ((config (configuration-file config))
|
| 127 | (debug? (avahi-configuration-debug? config))
|
| 128 | (avahi (avahi-configuration-avahi config)))
|
| 129 | (list (shepherd-service
|
| 130 | (documentation "Run the Avahi mDNS/DNS-SD responder.")
|
| 131 | (provision '(avahi-daemon))
|
| 132 | (requirement '(user-processes dbus-system networking))
|
| 133 |
|
| 134 | (start #~(make-systemd-constructor
|
| 135 | (list #$(file-append avahi "/sbin/avahi-daemon")
|
| 136 | #$@(if debug? #~("--debug") #~())
|
| 137 | "-f" #$config)
|
| 138 | (list (endpoint
|
| 139 | (make-socket-address
|
| 140 | AF_UNIX
|
| 141 | "/run/avahi-daemon/socket")))
|
| 142 | #:lazy-start? #f
|
| 143 | #:log-file "/var/log/avahi-daemon.log"))
|
| 144 | (stop #~(make-systemd-destructor))
|
| 145 | (actions (list (shepherd-configuration-action config)))))))
|
| 146 |
|
| 147 | (define avahi-service-type
|
| 148 | (let ((avahi-package (compose list avahi-configuration-avahi)))
|
| 149 | (service-type (name 'avahi)
|
| 150 | (description
|
| 151 | "Run @command{avahi-daemon}, a host and service discovery
|
| 152 | daemon that implements the multicast DNS (mDNS) and DNS service
|
| 153 | discovery (DNS-SD) protocols. Additionally, extend the C library's name
|
| 154 | service switch (NSS) with support for @code{.local} host name resolution.")
|
| 155 | (extensions
|
| 156 | (list (service-extension shepherd-root-service-type
|
| 157 | avahi-shepherd-service)
|
| 158 | (service-extension dbus-root-service-type
|
| 159 | avahi-package)
|
| 160 | (service-extension account-service-type
|
| 161 | (const %avahi-accounts))
|
| 162 | (service-extension activation-service-type
|
| 163 | (const %avahi-activation))
|
| 164 | (service-extension nscd-service-type
|
| 165 | (const (list nss-mdns)))
|
| 166 |
|
| 167 | |
| 168 | |
| 169 | (service-extension profile-service-type
|
| 170 | avahi-package)))
|
| 171 | (default-value (avahi-configuration)))))
|
| 172 |
|
| 173 | |