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