···
2
-
{ config, lib, pkgs, ... }:
2
+
{ config, lib, utils, pkgs, ... }:
···
cfg = config.services.avahi;
10
-
inherit (pkgs) avahi;
10
+
# We must escape interfaces due to the systemd interpretation
11
+
subsystemDevice = interface:
12
+
"sys-subsystem-net-devices-${utils.escapeSystemdPath interface}.device";
avahiDaemonConf = with cfg; pkgs.writeText "avahi-daemon.conf" ''
···
browse-domains=${concatStringsSep ", " browseDomains}
use-ipv4=${if ipv4 then "yes" else "no"}
use-ipv6=${if ipv6 then "yes" else "no"}
26
+
${optionalString (interfaces!=null) "allow-interfaces=${concatStringsSep "," interfaces}"}
enable-wide-area=${if wideArea then "yes" else "no"}
29
-
disable-publishing=${if publishing then "no" else "yes"}
32
+
disable-publishing=${if publish.enable then "no" else "yes"}
33
+
disable-user-service-publishing=${if publish.userServices then "no" else "yes"}
34
+
publish-addresses=${if publish.userServices || publish.addresses then "yes" else "no"}
35
+
publish-hinfo=${if publish.hinfo then "yes" else "no"}
36
+
publish-workstation=${if publish.workstation then "yes" else "no"}
37
+
publish-domain=${if publish.domain then "yes" else "no"}
···
description = ''Whether to use IPv6'';
85
+
interfaces = mkOption {
86
+
type = types.nullOr (types.listOf types.str);
89
+
List of network interfaces that should be used by the <command>avahi-daemon</command>.
90
+
Other interfaces will be ignored. If <literal>null</literal> all local interfaces
91
+
except loopback and point-to-point will be used.
description = ''Whether to enable wide-area service discovery.'';
82
-
publishing = mkOption {
84
-
description = ''Whether to allow publishing.'';
101
+
enable = mkOption {
103
+
description = ''Whether to allow publishing in general.'';
106
+
userServices = mkOption {
108
+
description = ''Whether to publish user services. Will set <literal>addresses=true</literal>.'';
111
+
addresses = mkOption {
113
+
description = ''Whether to register mDNS address records for all local IP addresses.'';
119
+
Whether to register an mDNS HINFO record which contains information about the
120
+
local operating system and CPU.
124
+
workstation = mkOption {
126
+
description = ''Whether to register a service of type "_workstation._tcp" on the local LAN.'';
129
+
domain = mkOption {
131
+
description = ''Whether to announce the locally used domain name for browsing by other hosts.'';
···
system.nssModules = optional cfg.nssmdns pkgs.nssmdns;
121
-
environment.systemPackages = [ avahi ];
170
+
environment.systemPackages = [ pkgs.avahi ];
123
-
jobs.avahi_daemon =
124
-
{ name = "avahi-daemon";
172
+
systemd.services.avahi-daemon =
174
+
deps = optionals (cfg.interfaces!=null) (map subsystemDevice cfg.interfaces);
176
+
{ description = "Avahi daemon";
177
+
wantedBy = [ "ip-up.target" ];
180
+
before = [ "ip-up.target" ];
181
+
# Receive restart event after resume
182
+
partOf = [ "post-resume.target" ];
184
+
path = [ pkgs.coreutils pkgs.avahi ];
186
+
preStart = "mkdir -p /var/run/avahi-daemon";
130
-
export PATH="${avahi}/bin:${avahi}/sbin:$PATH"
# Make NSS modules visible so that `avahi_nss_support ()' can
# return a sensible value.
export LD_LIBRARY_PATH="${config.system.nssModules.path}"
136
-
mkdir -p /var/run/avahi-daemon
138
-
exec ${avahi}/sbin/avahi-daemon --syslog -f "${avahiDaemonConf}"
194
+
exec ${pkgs.avahi}/sbin/avahi-daemon --syslog -f "${avahiDaemonConf}"
services.dbus.enable = true;
143
-
services.dbus.packages = [avahi];
199
+
services.dbus.packages = [ pkgs.avahi ];
# Enabling Avahi without exposing it in the firewall doesn't make