Commit | Line | Data |
---|---|---|
f4561be2 | 1 | ;;; GNU Guix --- Functional package management for GNU |
59a6780f | 2 | ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
f4561be2 LC |
3 | ;;; |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (gnu services avahi) | |
20 | #:use-module (gnu services) | |
0adfe95a | 21 | #:use-module (gnu services base) |
0190c1c0 | 22 | #:use-module (gnu services shepherd) |
0adfe95a | 23 | #:use-module (gnu services dbus) |
f4561be2 LC |
24 | #:use-module (gnu system shadow) |
25 | #:use-module (gnu packages avahi) | |
5e25ebe2 | 26 | #:use-module (gnu packages admin) |
2e04ab71 | 27 | #:use-module (guix deprecation) |
0adfe95a | 28 | #:use-module (guix records) |
f4561be2 | 29 | #:use-module (guix gexp) |
24e96431 | 30 | #:export (avahi-configuration |
2e04ab71 LC |
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 | ||
24e96431 | 43 | avahi-service |
893106cb | 44 | avahi-service-type)) |
f4561be2 LC |
45 | |
46 | ;;; Commentary: | |
47 | ;;; | |
48 | ;;; This module provides service definitions for the Avahi | |
49 | ;;; "zero-configuration" tool set. | |
50 | ;;; | |
51 | ;;; Code: | |
52 | ||
0adfe95a LC |
53 | (define-record-type* <avahi-configuration> |
54 | avahi-configuration make-avahi-configuration | |
55 | avahi-configuration? | |
56 | (avahi avahi-configuration-avahi ;<package> | |
57 | (default avahi)) | |
c8695f32 LC |
58 | (debug? avahi-configuration-debug? ;Boolean |
59 | (default #f)) | |
2e04ab71 LC |
60 | (host-name avahi-configuration-host-name ;string | #f |
61 | (default #f)) | |
62 | (publish? avahi-configuration-publish? ;boolean | |
63 | (default #t)) | |
37084ba5 LC |
64 | |
65 | ;; The default for this was #t in Avahi 0.6.31 and became #f in 0.7. For | |
66 | ;; now we stick to the old default. | |
67 | (publish-workstation? avahi-configuration-publish-workstation? ;Boolean | |
68 | (default #t)) | |
69 | ||
2e04ab71 LC |
70 | (ipv4? avahi-configuration-ipv4? ;Boolean |
71 | (default #t)) | |
72 | (ipv6? avahi-configuration-ipv6? ;Boolean | |
73 | (default #t)) | |
74 | (wide-area? avahi-configuration-wide-area? ;Boolean | |
75 | (default #f)) | |
76 | (domains-to-browse avahi-configuration-domains-to-browse ;list of strings | |
77 | (default '()))) | |
0adfe95a LC |
78 | |
79 | (define* (configuration-file config) | |
80 | "Return an avahi-daemon configuration file based on CONFIG, an | |
81 | <avahi-configuration>." | |
f4561be2 LC |
82 | (define (bool value) |
83 | (if value "yes\n" "no\n")) | |
84 | ||
0adfe95a LC |
85 | (define host-name (avahi-configuration-host-name config)) |
86 | ||
be1c2c54 LC |
87 | (plain-file "avahi-daemon.conf" |
88 | (string-append | |
89 | "[server]\n" | |
90 | (if host-name | |
91 | (string-append "host-name=" host-name "\n") | |
92 | "") | |
f4561be2 | 93 | |
0adfe95a LC |
94 | "browse-domains=" (string-join |
95 | (avahi-configuration-domains-to-browse | |
96 | config)) | |
be1c2c54 | 97 | "\n" |
0adfe95a LC |
98 | "use-ipv4=" (bool (avahi-configuration-ipv4? config)) |
99 | "use-ipv6=" (bool (avahi-configuration-ipv6? config)) | |
be1c2c54 | 100 | "[wide-area]\n" |
0adfe95a | 101 | "enable-wide-area=" (bool (avahi-configuration-wide-area? config)) |
be1c2c54 | 102 | "[publish]\n" |
0adfe95a | 103 | "disable-publishing=" |
37084ba5 LC |
104 | (bool (not (avahi-configuration-publish? config))) |
105 | "publish-workstation=" | |
106 | (bool (avahi-configuration-publish-workstation? config))))) | |
0adfe95a LC |
107 | |
108 | (define %avahi-accounts | |
109 | ;; Account and group for the Avahi daemon. | |
110 | (list (user-group (name "avahi") (system? #t)) | |
111 | (user-account | |
112 | (name "avahi") | |
113 | (group "avahi") | |
114 | (system? #t) | |
115 | (comment "Avahi daemon user") | |
116 | (home-directory "/var/empty") | |
9e41130b | 117 | (shell (file-append shadow "/sbin/nologin"))))) |
0adfe95a LC |
118 | |
119 | (define %avahi-activation | |
120 | ;; Activation gexp. | |
121 | #~(begin | |
122 | (use-modules (guix build utils)) | |
ad7a807d | 123 | (mkdir-p "/run/avahi-daemon"))) |
0adfe95a | 124 | |
d4053c71 AK |
125 | (define (avahi-shepherd-service config) |
126 | "Return a list of <shepherd-service> for CONFIG." | |
0adfe95a | 127 | (let ((config (configuration-file config)) |
c8695f32 | 128 | (debug? (avahi-configuration-debug? config)) |
0adfe95a | 129 | (avahi (avahi-configuration-avahi config))) |
d4053c71 | 130 | (list (shepherd-service |
0adfe95a LC |
131 | (documentation "Run the Avahi mDNS/DNS-SD responder.") |
132 | (provision '(avahi-daemon)) | |
59a6780f | 133 | (requirement '(user-processes dbus-system networking)) |
0adfe95a LC |
134 | |
135 | (start #~(make-forkexec-constructor | |
9fc037fe | 136 | (list #$(file-append avahi "/sbin/avahi-daemon") |
c8695f32 LC |
137 | "--daemonize" |
138 | #$@(if debug? #~("--debug") #~()) | |
139 | "-f" #$config) | |
ad7a807d | 140 | #:pid-file "/run/avahi-daemon/pid")) |
0adfe95a LC |
141 | (stop #~(make-kill-destructor)))))) |
142 | ||
143 | (define avahi-service-type | |
1065bed9 LC |
144 | (let ((avahi-package (compose list avahi-configuration-avahi))) |
145 | (service-type (name 'avahi) | |
21b71b01 LC |
146 | (description |
147 | "Run @command{avahi-daemon}, a host and service discovery | |
148 | daemon that implements the multicast DNS (mDNS) and DNS service | |
149 | discovery (DNS-SD) protocols. Additionally, extend the C library's name | |
150 | service switch (NSS) with support for @code{.local} host name resolution.") | |
1065bed9 | 151 | (extensions |
d4053c71 AK |
152 | (list (service-extension shepherd-root-service-type |
153 | avahi-shepherd-service) | |
1065bed9 LC |
154 | (service-extension dbus-root-service-type |
155 | avahi-package) | |
156 | (service-extension account-service-type | |
157 | (const %avahi-accounts)) | |
158 | (service-extension activation-service-type | |
159 | (const %avahi-activation)) | |
160 | (service-extension nscd-service-type | |
9859b5c1 | 161 | (const (list nss-mdns))) |
1065bed9 LC |
162 | |
163 | ;; Provide 'avahi-browse', 'avahi-resolve', etc. in | |
164 | ;; the system profile. | |
165 | (service-extension profile-service-type | |
2e04ab71 LC |
166 | avahi-package))) |
167 | (default-value (avahi-configuration))))) | |
168 | ||
169 | (define-deprecated (avahi-service #:key (avahi avahi) debug? | |
170 | host-name | |
171 | (publish? #t) | |
172 | (ipv4? #t) (ipv6? #t) | |
173 | wide-area? | |
174 | (domains-to-browse '())) | |
175 | avahi-service-type | |
f4561be2 LC |
176 | "Return a service that runs @command{avahi-daemon}, a system-wide |
177 | mDNS/DNS-SD responder that allows for service discovery and | |
f460f8da | 178 | \"zero-configuration\" host name lookups (see @uref{https://avahi.org/}), and |
cc9c1f39 LC |
179 | extends the name service cache daemon (nscd) so that it can resolve |
180 | @code{.local} host names using | |
1065bed9 LC |
181 | @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally, |
182 | add the @var{avahi} package to the system profile so that commands such as | |
183 | @command{avahi-browse} are directly usable. | |
f4561be2 LC |
184 | |
185 | If @var{host-name} is different from @code{#f}, use that as the host name to | |
186 | publish for this machine; otherwise, use the machine's actual host name. | |
187 | ||
188 | When @var{publish?} is true, publishing of host names and services is allowed; | |
189 | in particular, avahi-daemon will publish the machine's host name and IP | |
190 | address via mDNS on the local network. | |
191 | ||
192 | When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled. | |
193 | ||
194 | Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6 | |
195 | sockets." | |
0adfe95a LC |
196 | (service avahi-service-type |
197 | (avahi-configuration | |
c8695f32 | 198 | (avahi avahi) (debug? debug?) (host-name host-name) |
0adfe95a LC |
199 | (publish? publish?) (ipv4? ipv4?) (ipv6? ipv6?) |
200 | (wide-area? wide-area?) | |
201 | (domains-to-browse domains-to-browse)))) | |
f4561be2 LC |
202 | |
203 | ;;; avahi.scm ends here |