1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
29 ;;; This module provides service definitions for the Avahi
30 ;;; "zero-configuration" tool set.
34 (define* (configuration-file #:key host-name publish?
35 ipv4? ipv6? wide-area? domains-to-browse)
36 "Return an avahi-daemon configuration file."
38 (if value "yes\n" "no\n"))
40 (text-file "avahi-daemon.conf"
44 (string-append "host-name=" host-name "\n")
47 "browse-domains=" (string-join domains-to-browse)
49 "use-ipv4=" (bool ipv4?)
50 "use-ipv6=" (bool ipv6?)
52 "enable-wide-area=" (bool wide-area?)
54 "disable-publishing=" (bool (not publish?)))))
56 (define* (avahi-service #:key (avahi avahi)
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.
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.
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.
73 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
75 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
77 (mlet %store-monad ((config (configuration-file #:host-name host-name
81 #:wide-area? wide-area?
86 (documentation "Run the Avahi mDNS/DNS-SD responder.")
87 (provision '(avahi-daemon))
88 (requirement '(dbus-system networking))
90 (start #~(make-forkexec-constructor
91 (list (string-append #$avahi "/sbin/avahi-daemon")
92 "--syslog" "-f" #$config)))
93 (stop #~(make-kill-destructor))
95 (use-modules (guix build utils))
96 (mkdir-p "/var/run/avahi-daemon")))
98 (user-groups (list (user-group
101 (user-accounts (list (user-account
105 (comment "Avahi daemon user")
106 (home-directory "/var/empty")
108 "/run/current-system/profile/sbin/nologin"))))))))
110 ;;; avahi.scm ends here