aboutsummaryrefslogtreecommitdiff
path: root/gnu/services/avahi.scm
blob: 89478cb997da0339426126e76d61e9265cf1218f (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu services avahi)
  #:use-module (gnu services)
  #:use-module (gnu system shadow)
  #:use-module (gnu packages avahi)
  #:use-module (guix monads)
  #:use-module (guix store)
  #:use-module (guix gexp)
  #:export (avahi-service))

;;; Commentary:
;;;
;;; This module provides service definitions for the Avahi
;;; "zero-configuration" tool set.
;;;
;;; Code:

(define* (configuration-file #:key host-name publish?
                             ipv4? ipv6? wide-area? domains-to-browse)
  "Return an avahi-daemon configuration file."
  (define (bool value)
    (if value "yes\n" "no\n"))

  (text-file "avahi-daemon.conf"
             (string-append
              "[server]\n"
              (if host-name
                  (string-append "host-name=" host-name "\n")
                  "")

              "browse-domains=" (string-join domains-to-browse)
              "\n"
              "use-ipv4=" (bool ipv4?)
              "use-ipv6=" (bool ipv6?)
              "[wide-area]\n"
              "enable-wide-area=" (bool wide-area?)
              "[publish]\n"
              "disable-publishing=" (bool (not publish?)))))

(define* (avahi-service #:key (avahi avahi)
                        host-name
                        (publish? #t)
                        (ipv4? #t) (ipv6? #t)
                        wide-area?
                        (domains-to-browse '()))
  "Return a service that runs @command{avahi-daemon}, a system-wide
mDNS/DNS-SD responder that allows for service discovery and
\"zero-configuration\" host name lookups.

If @var{host-name} is different from @code{#f}, use that as the host name to
publish for this machine; otherwise, use the machine's actual host name.

When @var{publish?} is true, publishing of host names and services is allowed;
in particular, avahi-daemon will publish the machine's host name and IP
address via mDNS on the local network.

When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.

Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
sockets."
  (mlet %store-monad ((config (configuration-file #:host-name host-name
                                                  #:publish? publish?
                                                  #:ipv4? ipv4?
                                                  #:ipv6? ipv6?
                                                  #:wide-area? wide-area?
                                                  #:domains-to-browse
                                                  domains-to-browse)))
    (return
     (service
      (documentation "Run the Avahi mDNS/DNS-SD responder.")
      (provision '(avahi-daemon))
      (requirement '(dbus-system networking))

      (start #~(make-forkexec-constructor
                (list (string-append #$avahi "/sbin/avahi-daemon")
                      "--syslog" "-f" #$config)))
      (stop #~(make-kill-destructor))
      (activate #~(begin
                    (use-modules (guix build utils))
                    (mkdir-p "/var/run/avahi-daemon")))

      (user-groups (list (user-group
                          (name "avahi")
                          (system? #t))))
      (user-accounts (list (user-account
                            (name "avahi")
                            (group "avahi")
                            (system? #t)
                            (comment "Avahi daemon user")
                            (home-directory "/var/empty")
                            (shell
                             "/run/current-system/profile/sbin/nologin"))))))))

;;; avahi.scm ends here
100'>2021-01-21doc: cookbook: Add "Guix System Image API" section....* doc/guix-cookbook.texi (Guix System Image API): New section. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> Joshua Branson 2021-01-20doc: Replace TP with Weblate mentions....* doc/contributing.texi: Replace link to TP with a link to Weblate. * doc/guix.texi: Replace link to TP with a link to Weblate. * doc/guix-cookbook.texi: Replace link to TP with a link to Weblate. Julien Lepiller 2020-12-23doc: cookbook: Fix "fiction-less" typo....* doc/guix-cookbook.texi (Guix Profiles in Practice): Change "friction-less" to "frictionless". Pierre Neidhardt 2020-10-17doc: cookbook: Balance parens in custom kernel examples....* doc/guix-cookbook.texi (Customizing the Kernel): Add missing paren in example. Remove extra parens in other example. Ludovic Courtès 2020-10-15doc: cookbook: Clarify what keywords are....* doc/guix-cookbook.texi (A Scheme Crash Course): Clarify what keywords are. Ludovic Courtès 2020-10-15doc: Add "Build Utilities" section....* doc/guix.texi (Build Utilities): New section. (Defining Packages): Refer to it. (Build Systems): Likewise. * doc/guix-cookbook.texi (Extended example): Likewise. Ludovic Courtès 2020-10-15doc: cookbook: Use @code for the identifiers of utility functions....* doc/guix-cookbook.texi (Utility functions): Use @code instead of @asis. Ludovic Courtès 2020-10-15doc: cookbook: More "#true" and "#false"....* doc/guix-cookbook.texi (Extended example) (Customizing the Kernel, Running Guix on a Linode Server): Use #true and #false. Ludovic Courtès 2020-10-15doc: cookbook: Use @var for meta-syntactic variables....* doc/guix-cookbook.texi (Extended example): Use @var for meta-syntactic variables in 'modify-phases' description. Ludovic Courtès 2020-10-15doc: cookbook: Fix 'let' form in example....* doc/guix-cookbook.texi (Extended example): Fix 'let' form in example. Ludovic Courtès 2020-10-14services: nginx: Add lua module....* gnu/services/web.scm (<nginx-configuration>) [lua-package-path, lua-package-cpath]: New record types. * gnu/services/web.scm (default-nginx-config): Use them. * doc/guix.texi (Web Services): Document this. * doc/guix-cookbook.texi (System Configuration): Document this. Oleg Pykhalov 2020-10-14doc: cookbook: Mention "#true" and "#false"....* doc/guix-cookbook.texi (A Scheme Crash Course): Mention "#true" and "#false". (Extended example): Likewise. Ludovic Courtès 2020-09-09doc: cookbook: Adding a section "Running Guix on a Linode Server"...* doc/guix-cookbook.texi (Running Guix on a Linode Server): I added a section that explains how to run guix on a linode server. Thanks Chris Webber! Signed-off-by: Ludovic Courtès <ludo@gnu.org> Joshua Branson 2020-08-23doc: cookbook: Add chapter about Guix environment....* doc/guix-cookbook.texi (Environment management): New chapter. Oleg Pykhalov 2020-07-09doc: cookbook: Fix ‘file system’ spelling....* doc/guix-cookbook.texi (Getting help, Customizing the Kernel): Fix ‘file system’ spelling. Tobias Geerinckx-Rice 2020-06-28doc: cookbook: Fix encoding of "André"....This is a followup to f8945734a5abff69644284231cc47fb67456657b. * doc/guix-cookbook.texi: Encode "André" as UTF-8, not ISO-8859-1. Ludovic Courtès 2020-06-28doc: cookbook: Update entry about getting substitutes through Tor....* doc/guix-cookbook.texi (Getting substitutes from Tor): Update section warning to mention the use of torsocks when pulling. André Batista 2020-06-23doc: cookbook: Fix typos....* doc/guix-cookbook.texi (Extended example): Fix typos. Ludovic Courtès 2020-06-23doc: cookbook: Tweak intro to the REPL....* doc/guix-cookbook.texi (A Scheme Crash Course): Reword first paragraph. Remove extra paren. Ludovic Courtès 2020-06-23doc: cookbook: Mention "guix hash -rx" for Git checkouts....* doc/guix-cookbook.texi (Extended example): Mention "guix hash -rx ." Ludovic Courtès 2020-06-23doc: cookbook: Clarify 'git-fetch' conventions....* doc/guix-cookbook.texi (Extended example): Clarify use of 'git-file-name' and 'git-version'. Ludovic Courtès 2020-06-04doc: cookbook: Add entry about getting substitutes through Tor....* doc/guix-cookbook.texi (Getting substitutes from Tor): New section. Brice Waegeneire