Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / services / avahi.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
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)
21 #:use-module (gnu system shadow)
22 #:use-module (gnu packages avahi)
23 #:use-module (gnu packages admin)
24 #:use-module (guix monads)
25 #:use-module (guix store)
26 #:use-module (guix gexp)
27 #:export (avahi-service))
28
29 ;;; Commentary:
30 ;;;
31 ;;; This module provides service definitions for the Avahi
32 ;;; "zero-configuration" tool set.
33 ;;;
34 ;;; Code:
35
36 (define* (configuration-file #:key host-name publish?
37 ipv4? ipv6? wide-area? domains-to-browse)
38 "Return an avahi-daemon configuration file."
39 (define (bool value)
40 (if value "yes\n" "no\n"))
41
42 (text-file "avahi-daemon.conf"
43 (string-append
44 "[server]\n"
45 (if host-name
46 (string-append "host-name=" host-name "\n")
47 "")
48
49 "browse-domains=" (string-join domains-to-browse)
50 "\n"
51 "use-ipv4=" (bool ipv4?)
52 "use-ipv6=" (bool ipv6?)
53 "[wide-area]\n"
54 "enable-wide-area=" (bool wide-area?)
55 "[publish]\n"
56 "disable-publishing=" (bool (not publish?)))))
57
58 (define* (avahi-service #:key (avahi avahi)
59 host-name
60 (publish? #t)
61 (ipv4? #t) (ipv6? #t)
62 wide-area?
63 (domains-to-browse '()))
64 "Return a service that runs @command{avahi-daemon}, a system-wide
65 mDNS/DNS-SD responder that allows for service discovery and
66 \"zero-configuration\" host name lookups (see @uref{http://avahi.org/}).
67
68 If @var{host-name} is different from @code{#f}, use that as the host name to
69 publish for this machine; otherwise, use the machine's actual host name.
70
71 When @var{publish?} is true, publishing of host names and services is allowed;
72 in particular, avahi-daemon will publish the machine's host name and IP
73 address via mDNS on the local network.
74
75 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
76
77 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
78 sockets."
79 (mlet %store-monad ((config (configuration-file #:host-name host-name
80 #:publish? publish?
81 #:ipv4? ipv4?
82 #:ipv6? ipv6?
83 #:wide-area? wide-area?
84 #:domains-to-browse
85 domains-to-browse)))
86 (return
87 (service
88 (documentation "Run the Avahi mDNS/DNS-SD responder.")
89 (provision '(avahi-daemon))
90 (requirement '(dbus-system networking))
91
92 (start #~(make-forkexec-constructor
93 (list (string-append #$avahi "/sbin/avahi-daemon")
94 "--syslog" "-f" #$config)))
95 (stop #~(make-kill-destructor))
96 (activate #~(begin
97 (use-modules (guix build utils))
98 (mkdir-p "/var/run/avahi-daemon")))
99
100 (user-groups (list (user-group
101 (name "avahi")
102 (system? #t))))
103 (user-accounts (list (user-account
104 (name "avahi")
105 (group "avahi")
106 (system? #t)
107 (comment "Avahi daemon user")
108 (home-directory "/var/empty")
109 (shell
110 #~(string-append #$shadow "/sbin/nologin")))))))))
111
112 ;;; avahi.scm ends here