Commit | Line | Data |
---|---|---|
f4561be2 | 1 | ;;; GNU Guix --- Functional package management for GNU |
e87f0591 | 2 | ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org> |
f4561be2 LC |
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) | |
e87f0591 | 24 | #:use-module (guix store) |
f4561be2 LC |
25 | #:use-module (guix gexp) |
26 | #:export (avahi-service)) | |
27 | ||
28 | ;;; Commentary: | |
29 | ;;; | |
30 | ;;; This module provides service definitions for the Avahi | |
31 | ;;; "zero-configuration" tool set. | |
32 | ;;; | |
33 | ;;; Code: | |
34 | ||
35 | (define* (configuration-file #:key host-name publish? | |
36 | ipv4? ipv6? wide-area? domains-to-browse) | |
37 | "Return an avahi-daemon configuration file." | |
38 | (define (bool value) | |
39 | (if value "yes\n" "no\n")) | |
40 | ||
41 | (text-file "avahi-daemon.conf" | |
42 | (string-append | |
43 | "[server]\n" | |
44 | (if host-name | |
45 | (string-append "host-name=" host-name "\n") | |
46 | "") | |
47 | ||
48 | "browse-domains=" (string-join domains-to-browse) | |
49 | "\n" | |
50 | "use-ipv4=" (bool ipv4?) | |
51 | "use-ipv6=" (bool ipv6?) | |
52 | "[wide-area]\n" | |
53 | "enable-wide-area=" (bool wide-area?) | |
54 | "[publish]\n" | |
55 | "disable-publishing=" (bool (not publish?))))) | |
56 | ||
57 | (define* (avahi-service #:key (avahi avahi) | |
58 | host-name | |
59 | (publish? #t) | |
60 | (ipv4? #t) (ipv6? #t) | |
61 | wide-area? | |
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. | |
66 | ||
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. | |
69 | ||
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. | |
73 | ||
74 | When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled. | |
75 | ||
76 | Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6 | |
77 | sockets." | |
78 | (mlet %store-monad ((config (configuration-file #:host-name host-name | |
79 | #:publish? publish? | |
80 | #:ipv4? ipv4? | |
81 | #:ipv6? ipv6? | |
82 | #:wide-area? wide-area? | |
83 | #:domains-to-browse | |
84 | domains-to-browse))) | |
85 | (return | |
86 | (service | |
87 | (documentation "Run the Avahi mDNS/DNS-SD responder.") | |
88 | (provision '(avahi-daemon)) | |
89 | (requirement '(dbus-system networking)) | |
90 | ||
91 | (start #~(make-forkexec-constructor | |
1c6b445b LC |
92 | (list (string-append #$avahi "/sbin/avahi-daemon") |
93 | "--syslog" "-f" #$config))) | |
f4561be2 LC |
94 | (stop #~(make-kill-destructor)) |
95 | (activate #~(begin | |
96 | (use-modules (guix build utils)) | |
97 | (mkdir-p "/var/run/avahi-daemon"))) | |
98 | ||
99 | (user-groups (list (user-group | |
41717509 LC |
100 | (name "avahi") |
101 | (system? #t)))) | |
f4561be2 LC |
102 | (user-accounts (list (user-account |
103 | (name "avahi") | |
104 | (group "avahi") | |
459dd9ea | 105 | (system? #t) |
f4561be2 LC |
106 | (comment "Avahi daemon user") |
107 | (home-directory "/var/empty") | |
108 | (shell | |
109 | "/run/current-system/profile/sbin/nologin")))))))) | |
110 | ||
111 | ;;; avahi.scm ends here |