1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 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 store)
25 #:use-module (guix gexp)
26 #:export (avahi-service))
30 ;;; This module provides service definitions for the Avahi
31 ;;; "zero-configuration" tool set.
35 (define* (configuration-file #:key host-name publish?
36 ipv4? ipv6? wide-area? domains-to-browse)
37 "Return an avahi-daemon configuration file."
39 (if value "yes\n" "no\n"))
41 (text-file "avahi-daemon.conf"
45 (string-append "host-name=" host-name "\n")
48 "browse-domains=" (string-join domains-to-browse)
50 "use-ipv4=" (bool ipv4?)
51 "use-ipv6=" (bool ipv6?)
53 "enable-wide-area=" (bool wide-area?)
55 "disable-publishing=" (bool (not publish?)))))
57 (define* (avahi-service #:key (avahi avahi)
62 (domains-to-browse '()))
63 "Return a service that runs @command{avahi-daemon}, a system-wide
64 mDNS/DNS-SD responder that allows for service discovery and
65 \"zero-configuration\" host name lookups.
67 If @var{host-name} is different from @code{#f}, use that as the host name to
68 publish for this machine; otherwise, use the machine's actual host name.
70 When @var{publish?} is true, publishing of host names and services is allowed;
71 in particular, avahi-daemon will publish the machine's host name and IP
72 address via mDNS on the local network.
74 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
76 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
78 (mlet %store-monad ((config (configuration-file #:host-name host-name
82 #:wide-area? wide-area?
87 (documentation "Run the Avahi mDNS/DNS-SD responder.")
88 (provision '(avahi-daemon))
89 (requirement '(dbus-system networking))
91 (start #~(make-forkexec-constructor
92 (list (string-append #$avahi "/sbin/avahi-daemon")
93 "--syslog" "-f" #$config)))
94 (stop #~(make-kill-destructor))
96 (use-modules (guix build utils))
97 (mkdir-p "/var/run/avahi-daemon")))
99 (user-groups (list (user-group
102 (user-accounts (list (user-account
106 (comment "Avahi daemon user")
107 (home-directory "/var/empty")
109 "/run/current-system/profile/sbin/nologin"))))))))
111 ;;; avahi.scm ends here