2018-07-20 22:56:59 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2008-11-23 02:28:58 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.avahi;
|
|
|
|
|
2017-04-09 01:57:32 +02:00
|
|
|
yesNo = yes : if yes then "yes" else "no";
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
avahiDaemonConf = with cfg; pkgs.writeText "avahi-daemon.conf" ''
|
2008-03-06 18:11:22 +01:00
|
|
|
[server]
|
2012-09-07 10:58:53 +02:00
|
|
|
${# Users can set `networking.hostName' to the empty string, when getting
|
|
|
|
# a host name from DHCP. In that case, let Avahi take whatever the
|
|
|
|
# current host name is; setting `host-name' to the empty string in
|
|
|
|
# `avahi-daemon.conf' would be invalid.
|
2017-04-09 01:57:32 +02:00
|
|
|
optionalString (hostName != "") "host-name=${hostName}"}
|
2009-10-12 18:36:19 +02:00
|
|
|
browse-domains=${concatStringsSep ", " browseDomains}
|
2017-04-09 01:57:32 +02:00
|
|
|
use-ipv4=${yesNo ipv4}
|
|
|
|
use-ipv6=${yesNo ipv6}
|
2015-12-21 17:28:44 +01:00
|
|
|
${optionalString (interfaces!=null) "allow-interfaces=${concatStringsSep "," interfaces}"}
|
2016-05-29 03:01:47 +02:00
|
|
|
${optionalString (domainName!=null) "domain-name=${domainName}"}
|
2017-04-09 01:57:32 +02:00
|
|
|
allow-point-to-point=${yesNo allowPointToPoint}
|
2017-07-12 14:23:15 +02:00
|
|
|
${optionalString (cacheEntriesMax!=null) "cache-entries-max=${toString cacheEntriesMax}"}
|
2008-03-06 18:11:22 +01:00
|
|
|
|
|
|
|
[wide-area]
|
2017-04-09 01:57:32 +02:00
|
|
|
enable-wide-area=${yesNo wideArea}
|
2008-03-06 18:11:22 +01:00
|
|
|
|
|
|
|
[publish]
|
2017-04-09 01:57:32 +02:00
|
|
|
disable-publishing=${yesNo (!publish.enable)}
|
|
|
|
disable-user-service-publishing=${yesNo (!publish.userServices)}
|
|
|
|
publish-addresses=${yesNo (publish.userServices || publish.addresses)}
|
|
|
|
publish-hinfo=${yesNo publish.hinfo}
|
|
|
|
publish-workstation=${yesNo publish.workstation}
|
|
|
|
publish-domain=${yesNo publish.domain}
|
2017-04-18 15:10:24 +02:00
|
|
|
|
|
|
|
[reflector]
|
|
|
|
enable-reflector=${yesNo reflector}
|
2018-07-28 11:48:08 +02:00
|
|
|
${extraConfig}
|
2008-03-06 18:11:22 +01:00
|
|
|
'';
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
|
|
|
{
|
2019-05-22 20:59:34 +02:00
|
|
|
options.services.avahi = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run the Avahi daemon, which allows Avahi clients
|
|
|
|
to use Avahi's service discovery facilities and also allows
|
|
|
|
the local machine to advertise its presence and services
|
|
|
|
(through the mDNS responder implemented by `avahi-daemon').
|
|
|
|
'';
|
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
hostName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
|
|
|
defaultText = literalExample "config.networking.hostName";
|
|
|
|
description = ''
|
|
|
|
Host name advertised on the LAN. If not set, avahi will use the value
|
|
|
|
of <option>config.networking.hostName</option>.
|
|
|
|
'';
|
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
domainName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "local";
|
|
|
|
description = ''
|
|
|
|
Domain name for all advertisements.
|
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
browseDomains = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "0pointer.de" "zeroconf.org" ];
|
|
|
|
description = ''
|
|
|
|
List of non-local DNS domains to be browsed.
|
|
|
|
'';
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
ipv4 = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to use IPv4.";
|
|
|
|
};
|
2009-07-01 14:27:35 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
ipv6 = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to use IPv6.";
|
|
|
|
};
|
2009-07-01 14:27:35 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
interfaces = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
List of network interfaces that should be used by the <command>avahi-daemon</command>.
|
|
|
|
Other interfaces will be ignored. If <literal>null</literal>, all local interfaces
|
|
|
|
except loopback and point-to-point will be used.
|
|
|
|
'';
|
|
|
|
};
|
2016-05-29 03:01:47 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to open the firewall for UDP port 5353.
|
|
|
|
'';
|
|
|
|
};
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
allowPointToPoint = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description= ''
|
|
|
|
Whether to use POINTTOPOINT interfaces. Might make mDNS unreliable due to usually large
|
|
|
|
latencies with such links and opens a potential security hole by allowing mDNS access from Internet
|
|
|
|
connections.
|
|
|
|
'';
|
|
|
|
};
|
2008-03-06 21:56:50 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
wideArea = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to enable wide-area service discovery.";
|
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
reflector = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Reflect incoming mDNS requests to all allowed network interfaces.";
|
|
|
|
};
|
2015-12-21 17:28:44 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
extraServiceFiles = mkOption {
|
|
|
|
type = with types; attrsOf (either str path);
|
|
|
|
default = {};
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
ssh = "''${pkgs.avahi}/etc/avahi/services/ssh.service";
|
|
|
|
smb = '''
|
|
|
|
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
|
|
|
|
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
|
|
|
|
<service-group>
|
|
|
|
<name replace-wildcards="yes">%h</name>
|
|
|
|
<service>
|
|
|
|
<type>_smb._tcp</type>
|
|
|
|
<port>445</port>
|
|
|
|
</service>
|
|
|
|
</service-group>
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Specify custom service definitions which are placed in the avahi service directory.
|
|
|
|
See the <citerefentry><refentrytitle>avahi.service</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry> manpage for detailed information.
|
|
|
|
'';
|
|
|
|
};
|
2017-02-28 14:10:52 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
publish = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to allow publishing in general.";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
userServices = mkOption {
|
|
|
|
type = types.bool;
|
2017-04-18 15:10:24 +02:00
|
|
|
default = false;
|
2019-05-22 20:59:34 +02:00
|
|
|
description = "Whether to publish user services. Will set <literal>addresses=true</literal>.";
|
2017-04-18 15:10:24 +02:00
|
|
|
};
|
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
addresses = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to register mDNS address records for all local IP addresses.";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
hinfo = mkOption {
|
|
|
|
type = types.bool;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = false;
|
|
|
|
description = ''
|
2019-05-22 20:59:34 +02:00
|
|
|
Whether to register a mDNS HINFO record which contains information about the
|
|
|
|
local operating system and CPU.
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
workstation = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2017-07-12 14:23:15 +02:00
|
|
|
description = ''
|
2019-05-22 20:59:34 +02:00
|
|
|
Whether to register a service of type "_workstation._tcp" on the local LAN.
|
2017-07-12 14:23:15 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
domain = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether to announce the locally used domain name for browsing by other hosts.";
|
2018-07-28 11:48:08 +02:00
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
nssmdns = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the mDNS NSS (Name Service Switch) plug-in.
|
|
|
|
Enabling it allows applications to resolve names in the `.local'
|
|
|
|
domain by transparently querying the Avahi daemon.
|
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
cacheEntriesMax = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Number of resource records to be cached per interface. Use 0 to
|
|
|
|
disable caching. Avahi daemon defaults to 4096 if not set.
|
|
|
|
'';
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra config to append to avahi-daemon.conf.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-05-22 20:59:34 +02:00
|
|
|
users.users.avahi = {
|
|
|
|
description = "avahi-daemon privilege separation user";
|
|
|
|
home = "/var/empty";
|
|
|
|
group = "avahi";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
users.groups.avahi = {};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
system.nssModules = optional cfg.nssmdns pkgs.nssmdns;
|
2020-05-06 00:17:05 +02:00
|
|
|
system.nssDatabases.hosts = optionals cfg.nssmdns (mkMerge [
|
|
|
|
[ "mdns_minimal [NOTFOUND=return]" ]
|
|
|
|
(mkOrder 1501 [ "mdns" ]) # 1501 to ensure it's after dns
|
|
|
|
]);
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2015-12-21 17:28:44 +01:00
|
|
|
environment.systemPackages = [ pkgs.avahi ];
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
environment.etc = (mapAttrs' (n: v: nameValuePair
|
|
|
|
"avahi/services/${n}.service"
|
|
|
|
{ ${if types.path.check v then "source" else "text"} = v; }
|
|
|
|
) cfg.extraServiceFiles);
|
2016-10-15 22:30:50 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
systemd.sockets.avahi-daemon = {
|
|
|
|
description = "Avahi mDNS/DNS-SD Stack Activation Socket";
|
|
|
|
listenStreams = [ "/run/avahi-daemon/socket" ];
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
};
|
2016-10-15 22:30:50 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
systemd.tmpfiles.rules = [ "d /run/avahi-daemon - avahi avahi -" ];
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
systemd.services.avahi-daemon = {
|
|
|
|
description = "Avahi mDNS/DNS-SD Stack";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "avahi-daemon.socket" ];
|
2015-12-21 17:28:44 +01:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
# Make NSS modules visible so that `avahi_nss_support ()' can
|
|
|
|
# return a sensible value.
|
|
|
|
environment.LD_LIBRARY_PATH = config.system.nssModules.path;
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
path = [ pkgs.coreutils pkgs.avahi ];
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
serviceConfig = {
|
|
|
|
NotifyAccess = "main";
|
|
|
|
BusName = "org.freedesktop.Avahi";
|
|
|
|
Type = "dbus";
|
|
|
|
ExecStart = "${pkgs.avahi}/sbin/avahi-daemon --syslog -f ${avahiDaemonConf}";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2019-05-22 20:59:34 +02:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.dbus.enable = true;
|
2015-12-21 17:28:44 +01:00
|
|
|
services.dbus.packages = [ pkgs.avahi ];
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-05-22 20:59:34 +02:00
|
|
|
networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 5353 ];
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
2008-11-23 02:29:25 +01:00
|
|
|
}
|