gnu: geiser: Update to 0.8.
[jackhill/guix/guix.git] / gnu / services / avahi.scm
CommitLineData
f4561be2 1;;; GNU Guix --- Functional package management for GNU
e87f0591 2;;; Copyright © 2014, 2015 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
LC
21 #:use-module (gnu services base)
22 #:use-module (gnu services dmd)
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
LC
28 #:use-module (guix gexp)
29 #:export (avahi-service))
30
31;;; Commentary:
32;;;
33;;; This module provides service definitions for the Avahi
34;;; "zero-configuration" tool set.
35;;;
36;;; Code:
37
0adfe95a
LC
38 ;; TODO: Export.
39(define-record-type* <avahi-configuration>
40 avahi-configuration make-avahi-configuration
41 avahi-configuration?
42 (avahi avahi-configuration-avahi ;<package>
43 (default avahi))
44 (host-name avahi-configuration-host-name) ;string
45 (publish? avahi-configuration-publish?) ;Boolean
46 (ipv4? avahi-configuration-ipv4?) ;Boolean
47 (ipv6? avahi-configuration-ipv6?) ;Boolean
48 (wide-area? avahi-configuration-wide-area?) ;Boolean
49 (domains-to-browse avahi-configuration-domains-to-browse)) ;list of strings
50
51(define* (configuration-file config)
52 "Return an avahi-daemon configuration file based on CONFIG, an
53<avahi-configuration>."
f4561be2
LC
54 (define (bool value)
55 (if value "yes\n" "no\n"))
56
0adfe95a
LC
57 (define host-name (avahi-configuration-host-name config))
58
be1c2c54
LC
59 (plain-file "avahi-daemon.conf"
60 (string-append
61 "[server]\n"
62 (if host-name
63 (string-append "host-name=" host-name "\n")
64 "")
f4561be2 65
0adfe95a
LC
66 "browse-domains=" (string-join
67 (avahi-configuration-domains-to-browse
68 config))
be1c2c54 69 "\n"
0adfe95a
LC
70 "use-ipv4=" (bool (avahi-configuration-ipv4? config))
71 "use-ipv6=" (bool (avahi-configuration-ipv6? config))
be1c2c54 72 "[wide-area]\n"
0adfe95a 73 "enable-wide-area=" (bool (avahi-configuration-wide-area? config))
be1c2c54 74 "[publish]\n"
0adfe95a
LC
75 "disable-publishing="
76 (bool (not (avahi-configuration-publish? config))))))
77
78(define %avahi-accounts
79 ;; Account and group for the Avahi daemon.
80 (list (user-group (name "avahi") (system? #t))
81 (user-account
82 (name "avahi")
83 (group "avahi")
84 (system? #t)
85 (comment "Avahi daemon user")
86 (home-directory "/var/empty")
87 (shell #~(string-append #$shadow "/sbin/nologin")))))
88
89(define %avahi-activation
90 ;; Activation gexp.
91 #~(begin
92 (use-modules (guix build utils))
93 (mkdir-p "/var/run/avahi-daemon")))
94
95(define (avahi-dmd-service config)
96 "Return a list of <dmd-service> for CONFIG."
97 (let ((config (configuration-file config))
98 (avahi (avahi-configuration-avahi config)))
99 (list (dmd-service
100 (documentation "Run the Avahi mDNS/DNS-SD responder.")
101 (provision '(avahi-daemon))
102 (requirement '(dbus-system networking))
103
104 (start #~(make-forkexec-constructor
105 (list (string-append #$avahi "/sbin/avahi-daemon")
106 "--syslog" "-f" #$config)))
107 (stop #~(make-kill-destructor))))))
108
109(define avahi-service-type
110 (service-type (name 'avahi)
111 (extensions
112 (list (service-extension dmd-root-service-type
113 avahi-dmd-service)
114 (service-extension dbus-root-service-type
115 (compose list
116 avahi-configuration-avahi))
117 (service-extension account-service-type
118 (const %avahi-accounts))
119 (service-extension activation-service-type
120 (const %avahi-activation))
121 (service-extension nscd-service-type
122 (const (list nss-mdns)))))))
f4561be2
LC
123
124(define* (avahi-service #:key (avahi avahi)
125 host-name
126 (publish? #t)
127 (ipv4? #t) (ipv6? #t)
128 wide-area?
129 (domains-to-browse '()))
130 "Return a service that runs @command{avahi-daemon}, a system-wide
131mDNS/DNS-SD responder that allows for service discovery and
965a7332 132\"zero-configuration\" host name lookups (see @uref{http://avahi.org/}).
f4561be2
LC
133
134If @var{host-name} is different from @code{#f}, use that as the host name to
135publish for this machine; otherwise, use the machine's actual host name.
136
137When @var{publish?} is true, publishing of host names and services is allowed;
138in particular, avahi-daemon will publish the machine's host name and IP
139address via mDNS on the local network.
140
141When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
142
143Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
144sockets."
0adfe95a
LC
145 (service avahi-service-type
146 (avahi-configuration
147 (avahi avahi) (host-name host-name)
148 (publish? publish?) (ipv4? ipv4?) (ipv6? ipv6?)
149 (wide-area? wide-area?)
150 (domains-to-browse domains-to-browse))))
f4561be2
LC
151
152;;; avahi.scm ends here