Commit | Line | Data |
---|---|---|
f4561be2 | 1 | ;;; GNU Guix --- Functional package management for GNU |
8d9647d8 | 2 | ;;; Copyright © 2014-2020, 2022 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) | |
0adfe95a | 21 | #:use-module (gnu services base) |
0190c1c0 | 22 | #:use-module (gnu services shepherd) |
0adfe95a | 23 | #:use-module (gnu services dbus) |
f4561be2 LC |
24 | #:use-module (gnu system shadow) |
25 | #:use-module (gnu packages avahi) | |
5e25ebe2 | 26 | #:use-module (gnu packages admin) |
2e04ab71 | 27 | #:use-module (guix deprecation) |
0adfe95a | 28 | #:use-module (guix records) |
f4561be2 | 29 | #:use-module (guix gexp) |
24e96431 | 30 | #:export (avahi-configuration |
2e04ab71 LC |
31 | avahi-configuration? |
32 | ||
33 | avahi-configuration-avahi | |
34 | avahi-configuration-debug? | |
35 | avahi-configuration-host-name | |
36 | avahi-configuration-publish? | |
37 | avahi-configuration-publish-workstation? | |
38 | avahi-configuration-ipv4? | |
39 | avahi-configuration-ipv6? | |
40 | avahi-configuration-wide-area? | |
41 | avahi-configuration-domains-to-browse | |
42 | ||
893106cb | 43 | avahi-service-type)) |
f4561be2 LC |
44 | |
45 | ;;; Commentary: | |
46 | ;;; | |
47 | ;;; This module provides service definitions for the Avahi | |
48 | ;;; "zero-configuration" tool set. | |
49 | ;;; | |
50 | ;;; Code: | |
51 | ||
0adfe95a LC |
52 | (define-record-type* <avahi-configuration> |
53 | avahi-configuration make-avahi-configuration | |
54 | avahi-configuration? | |
892f1b72 | 55 | (avahi avahi-configuration-avahi ;file-like |
0adfe95a | 56 | (default avahi)) |
c8695f32 LC |
57 | (debug? avahi-configuration-debug? ;Boolean |
58 | (default #f)) | |
2e04ab71 LC |
59 | (host-name avahi-configuration-host-name ;string | #f |
60 | (default #f)) | |
61 | (publish? avahi-configuration-publish? ;boolean | |
62 | (default #t)) | |
37084ba5 LC |
63 | |
64 | ;; The default for this was #t in Avahi 0.6.31 and became #f in 0.7. For | |
65 | ;; now we stick to the old default. | |
66 | (publish-workstation? avahi-configuration-publish-workstation? ;Boolean | |
67 | (default #t)) | |
68 | ||
2e04ab71 LC |
69 | (ipv4? avahi-configuration-ipv4? ;Boolean |
70 | (default #t)) | |
71 | (ipv6? avahi-configuration-ipv6? ;Boolean | |
72 | (default #t)) | |
73 | (wide-area? avahi-configuration-wide-area? ;Boolean | |
74 | (default #f)) | |
75 | (domains-to-browse avahi-configuration-domains-to-browse ;list of strings | |
76 | (default '()))) | |
0adfe95a LC |
77 | |
78 | (define* (configuration-file config) | |
79 | "Return an avahi-daemon configuration file based on CONFIG, an | |
80 | <avahi-configuration>." | |
f4561be2 LC |
81 | (define (bool value) |
82 | (if value "yes\n" "no\n")) | |
83 | ||
0adfe95a LC |
84 | (define host-name (avahi-configuration-host-name config)) |
85 | ||
be1c2c54 LC |
86 | (plain-file "avahi-daemon.conf" |
87 | (string-append | |
88 | "[server]\n" | |
89 | (if host-name | |
90 | (string-append "host-name=" host-name "\n") | |
91 | "") | |
f4561be2 | 92 | |
0adfe95a LC |
93 | "browse-domains=" (string-join |
94 | (avahi-configuration-domains-to-browse | |
95 | config)) | |
be1c2c54 | 96 | "\n" |
0adfe95a LC |
97 | "use-ipv4=" (bool (avahi-configuration-ipv4? config)) |
98 | "use-ipv6=" (bool (avahi-configuration-ipv6? config)) | |
be1c2c54 | 99 | "[wide-area]\n" |
0adfe95a | 100 | "enable-wide-area=" (bool (avahi-configuration-wide-area? config)) |
be1c2c54 | 101 | "[publish]\n" |
0adfe95a | 102 | "disable-publishing=" |
37084ba5 LC |
103 | (bool (not (avahi-configuration-publish? config))) |
104 | "publish-workstation=" | |
105 | (bool (avahi-configuration-publish-workstation? config))))) | |
0adfe95a LC |
106 | |
107 | (define %avahi-accounts | |
108 | ;; Account and group for the Avahi daemon. | |
109 | (list (user-group (name "avahi") (system? #t)) | |
110 | (user-account | |
111 | (name "avahi") | |
112 | (group "avahi") | |
113 | (system? #t) | |
114 | (comment "Avahi daemon user") | |
115 | (home-directory "/var/empty") | |
9e41130b | 116 | (shell (file-append shadow "/sbin/nologin"))))) |
0adfe95a LC |
117 | |
118 | (define %avahi-activation | |
119 | ;; Activation gexp. | |
120 | #~(begin | |
121 | (use-modules (guix build utils)) | |
ad7a807d | 122 | (mkdir-p "/run/avahi-daemon"))) |
0adfe95a | 123 | |
d4053c71 AK |
124 | (define (avahi-shepherd-service config) |
125 | "Return a list of <shepherd-service> for CONFIG." | |
0adfe95a | 126 | (let ((config (configuration-file config)) |
c8695f32 | 127 | (debug? (avahi-configuration-debug? config)) |
0adfe95a | 128 | (avahi (avahi-configuration-avahi config))) |
d4053c71 | 129 | (list (shepherd-service |
0adfe95a LC |
130 | (documentation "Run the Avahi mDNS/DNS-SD responder.") |
131 | (provision '(avahi-daemon)) | |
59a6780f | 132 | (requirement '(user-processes dbus-system networking)) |
0adfe95a LC |
133 | |
134 | (start #~(make-forkexec-constructor | |
9fc037fe | 135 | (list #$(file-append avahi "/sbin/avahi-daemon") |
c8695f32 LC |
136 | "--daemonize" |
137 | #$@(if debug? #~("--debug") #~()) | |
138 | "-f" #$config) | |
ad7a807d | 139 | #:pid-file "/run/avahi-daemon/pid")) |
8d9647d8 LC |
140 | (stop #~(make-kill-destructor)) |
141 | (actions (list (shepherd-configuration-action config))))))) | |
0adfe95a LC |
142 | |
143 | (define avahi-service-type | |
1065bed9 LC |
144 | (let ((avahi-package (compose list avahi-configuration-avahi))) |
145 | (service-type (name 'avahi) | |
21b71b01 LC |
146 | (description |
147 | "Run @command{avahi-daemon}, a host and service discovery | |
148 | daemon that implements the multicast DNS (mDNS) and DNS service | |
149 | discovery (DNS-SD) protocols. Additionally, extend the C library's name | |
150 | service switch (NSS) with support for @code{.local} host name resolution.") | |
1065bed9 | 151 | (extensions |
d4053c71 AK |
152 | (list (service-extension shepherd-root-service-type |
153 | avahi-shepherd-service) | |
1065bed9 LC |
154 | (service-extension dbus-root-service-type |
155 | avahi-package) | |
156 | (service-extension account-service-type | |
157 | (const %avahi-accounts)) | |
158 | (service-extension activation-service-type | |
159 | (const %avahi-activation)) | |
160 | (service-extension nscd-service-type | |
9859b5c1 | 161 | (const (list nss-mdns))) |
1065bed9 LC |
162 | |
163 | ;; Provide 'avahi-browse', 'avahi-resolve', etc. in | |
164 | ;; the system profile. | |
165 | (service-extension profile-service-type | |
2e04ab71 LC |
166 | avahi-package))) |
167 | (default-value (avahi-configuration))))) | |
168 | ||
f4561be2 | 169 | ;;; avahi.scm ends here |