Commit | Line | Data |
---|---|---|
f4561be2 | 1 | ;;; GNU Guix --- Functional package management for GNU |
a68fdfea | 2 | ;;; Copyright © 2014, 2015, 2016, 2017, 2018 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) |
0adfe95a | 27 | #:use-module (guix records) |
f4561be2 | 28 | #:use-module (guix gexp) |
24e96431 TČ |
29 | #:export (avahi-configuration |
30 | avahi-service | |
893106cb | 31 | avahi-service-type)) |
f4561be2 LC |
32 | |
33 | ;;; Commentary: | |
34 | ;;; | |
35 | ;;; This module provides service definitions for the Avahi | |
36 | ;;; "zero-configuration" tool set. | |
37 | ;;; | |
38 | ;;; Code: | |
39 | ||
0adfe95a LC |
40 | ;; TODO: Export. |
41 | (define-record-type* <avahi-configuration> | |
42 | avahi-configuration make-avahi-configuration | |
43 | avahi-configuration? | |
44 | (avahi avahi-configuration-avahi ;<package> | |
45 | (default avahi)) | |
c8695f32 LC |
46 | (debug? avahi-configuration-debug? ;Boolean |
47 | (default #f)) | |
0adfe95a LC |
48 | (host-name avahi-configuration-host-name) ;string |
49 | (publish? avahi-configuration-publish?) ;Boolean | |
50 | (ipv4? avahi-configuration-ipv4?) ;Boolean | |
51 | (ipv6? avahi-configuration-ipv6?) ;Boolean | |
52 | (wide-area? avahi-configuration-wide-area?) ;Boolean | |
53 | (domains-to-browse avahi-configuration-domains-to-browse)) ;list of strings | |
54 | ||
55 | (define* (configuration-file config) | |
56 | "Return an avahi-daemon configuration file based on CONFIG, an | |
57 | <avahi-configuration>." | |
f4561be2 LC |
58 | (define (bool value) |
59 | (if value "yes\n" "no\n")) | |
60 | ||
0adfe95a LC |
61 | (define host-name (avahi-configuration-host-name config)) |
62 | ||
be1c2c54 LC |
63 | (plain-file "avahi-daemon.conf" |
64 | (string-append | |
65 | "[server]\n" | |
66 | (if host-name | |
67 | (string-append "host-name=" host-name "\n") | |
68 | "") | |
f4561be2 | 69 | |
0adfe95a LC |
70 | "browse-domains=" (string-join |
71 | (avahi-configuration-domains-to-browse | |
72 | config)) | |
be1c2c54 | 73 | "\n" |
0adfe95a LC |
74 | "use-ipv4=" (bool (avahi-configuration-ipv4? config)) |
75 | "use-ipv6=" (bool (avahi-configuration-ipv6? config)) | |
be1c2c54 | 76 | "[wide-area]\n" |
0adfe95a | 77 | "enable-wide-area=" (bool (avahi-configuration-wide-area? config)) |
be1c2c54 | 78 | "[publish]\n" |
0adfe95a LC |
79 | "disable-publishing=" |
80 | (bool (not (avahi-configuration-publish? config)))))) | |
81 | ||
82 | (define %avahi-accounts | |
83 | ;; Account and group for the Avahi daemon. | |
84 | (list (user-group (name "avahi") (system? #t)) | |
85 | (user-account | |
86 | (name "avahi") | |
87 | (group "avahi") | |
88 | (system? #t) | |
89 | (comment "Avahi daemon user") | |
90 | (home-directory "/var/empty") | |
9e41130b | 91 | (shell (file-append shadow "/sbin/nologin"))))) |
0adfe95a LC |
92 | |
93 | (define %avahi-activation | |
94 | ;; Activation gexp. | |
95 | #~(begin | |
96 | (use-modules (guix build utils)) | |
97 | (mkdir-p "/var/run/avahi-daemon"))) | |
98 | ||
d4053c71 AK |
99 | (define (avahi-shepherd-service config) |
100 | "Return a list of <shepherd-service> for CONFIG." | |
0adfe95a | 101 | (let ((config (configuration-file config)) |
c8695f32 | 102 | (debug? (avahi-configuration-debug? config)) |
0adfe95a | 103 | (avahi (avahi-configuration-avahi config))) |
d4053c71 | 104 | (list (shepherd-service |
0adfe95a LC |
105 | (documentation "Run the Avahi mDNS/DNS-SD responder.") |
106 | (provision '(avahi-daemon)) | |
107 | (requirement '(dbus-system networking)) | |
108 | ||
109 | (start #~(make-forkexec-constructor | |
9fc037fe | 110 | (list #$(file-append avahi "/sbin/avahi-daemon") |
c8695f32 LC |
111 | "--daemonize" |
112 | #$@(if debug? #~("--debug") #~()) | |
113 | "-f" #$config) | |
194ccecf | 114 | #:pid-file "/var/run/avahi-daemon/pid")) |
0adfe95a LC |
115 | (stop #~(make-kill-destructor)))))) |
116 | ||
117 | (define avahi-service-type | |
1065bed9 LC |
118 | (let ((avahi-package (compose list avahi-configuration-avahi))) |
119 | (service-type (name 'avahi) | |
21b71b01 LC |
120 | (description |
121 | "Run @command{avahi-daemon}, a host and service discovery | |
122 | daemon that implements the multicast DNS (mDNS) and DNS service | |
123 | discovery (DNS-SD) protocols. Additionally, extend the C library's name | |
124 | service switch (NSS) with support for @code{.local} host name resolution.") | |
1065bed9 | 125 | (extensions |
d4053c71 AK |
126 | (list (service-extension shepherd-root-service-type |
127 | avahi-shepherd-service) | |
1065bed9 LC |
128 | (service-extension dbus-root-service-type |
129 | avahi-package) | |
130 | (service-extension account-service-type | |
131 | (const %avahi-accounts)) | |
132 | (service-extension activation-service-type | |
133 | (const %avahi-activation)) | |
a68fdfea LC |
134 | |
135 | ;; Use 0.10 due to <https://bugs.gnu.org/30396>. | |
1065bed9 | 136 | (service-extension nscd-service-type |
a68fdfea | 137 | (const (list nss-mdns-0.10))) |
1065bed9 LC |
138 | |
139 | ;; Provide 'avahi-browse', 'avahi-resolve', etc. in | |
140 | ;; the system profile. | |
141 | (service-extension profile-service-type | |
142 | avahi-package)))))) | |
f4561be2 | 143 | |
c8695f32 | 144 | (define* (avahi-service #:key (avahi avahi) debug? |
f4561be2 LC |
145 | host-name |
146 | (publish? #t) | |
147 | (ipv4? #t) (ipv6? #t) | |
148 | wide-area? | |
149 | (domains-to-browse '())) | |
150 | "Return a service that runs @command{avahi-daemon}, a system-wide | |
151 | mDNS/DNS-SD responder that allows for service discovery and | |
cc9c1f39 LC |
152 | \"zero-configuration\" host name lookups (see @uref{http://avahi.org/}), and |
153 | extends the name service cache daemon (nscd) so that it can resolve | |
154 | @code{.local} host names using | |
1065bed9 LC |
155 | @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally, |
156 | add the @var{avahi} package to the system profile so that commands such as | |
157 | @command{avahi-browse} are directly usable. | |
f4561be2 LC |
158 | |
159 | If @var{host-name} is different from @code{#f}, use that as the host name to | |
160 | publish for this machine; otherwise, use the machine's actual host name. | |
161 | ||
162 | When @var{publish?} is true, publishing of host names and services is allowed; | |
163 | in particular, avahi-daemon will publish the machine's host name and IP | |
164 | address via mDNS on the local network. | |
165 | ||
166 | When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled. | |
167 | ||
168 | Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6 | |
169 | sockets." | |
0adfe95a LC |
170 | (service avahi-service-type |
171 | (avahi-configuration | |
c8695f32 | 172 | (avahi avahi) (debug? debug?) (host-name host-name) |
0adfe95a LC |
173 | (publish? publish?) (ipv4? ipv4?) (ipv6? ipv6?) |
174 | (wide-area? wide-area?) | |
175 | (domains-to-browse domains-to-browse)))) | |
f4561be2 LC |
176 | |
177 | ;;; avahi.scm ends here |