2008-11-23 01:28:58 +00:00
|
|
|
# Avahi daemon.
|
2018-07-20 21:56:59 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-03-06 17:11:22 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2008-11-23 01:28:58 +00:00
|
|
|
|
|
|
|
let
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
cfg = config.services.avahi;
|
|
|
|
|
2017-04-09 00:57:32 +01:00
|
|
|
yesNo = yes : if yes then "yes" else "no";
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
avahiDaemonConf = with cfg; pkgs.writeText "avahi-daemon.conf" ''
|
2008-03-06 17:11:22 +00:00
|
|
|
[server]
|
2012-09-07 09:58:53 +01: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 00:57:32 +01:00
|
|
|
optionalString (hostName != "") "host-name=${hostName}"}
|
2009-10-12 17:36:19 +01:00
|
|
|
browse-domains=${concatStringsSep ", " browseDomains}
|
2017-04-09 00:57:32 +01:00
|
|
|
use-ipv4=${yesNo ipv4}
|
|
|
|
use-ipv6=${yesNo ipv6}
|
2015-12-21 16:28:44 +00:00
|
|
|
${optionalString (interfaces!=null) "allow-interfaces=${concatStringsSep "," interfaces}"}
|
2016-05-29 02:01:47 +01:00
|
|
|
${optionalString (domainName!=null) "domain-name=${domainName}"}
|
2017-04-09 00:57:32 +01:00
|
|
|
allow-point-to-point=${yesNo allowPointToPoint}
|
2017-07-12 13:23:15 +01:00
|
|
|
${optionalString (cacheEntriesMax!=null) "cache-entries-max=${toString cacheEntriesMax}"}
|
2008-03-06 17:11:22 +00:00
|
|
|
|
|
|
|
[wide-area]
|
2017-04-09 00:57:32 +01:00
|
|
|
enable-wide-area=${yesNo wideArea}
|
2008-03-06 17:11:22 +00:00
|
|
|
|
|
|
|
[publish]
|
2017-04-09 00:57:32 +01: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 14:10:24 +01:00
|
|
|
|
|
|
|
[reflector]
|
|
|
|
enable-reflector=${yesNo reflector}
|
2018-07-28 10:48:08 +01:00
|
|
|
${extraConfig}
|
2008-03-06 17:11:22 +00:00
|
|
|
'';
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
in
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
{
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### interface
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
services.avahi = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
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').
|
|
|
|
'';
|
|
|
|
};
|
2009-07-01 13:27:35 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
hostName = mkOption {
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-12-07 11:03:50 +00:00
|
|
|
description = ''
|
|
|
|
Host name advertised on the LAN. If not set, avahi will use the value
|
|
|
|
of config.networking.hostName.
|
|
|
|
'';
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2009-07-01 13:27:35 +01:00
|
|
|
|
2016-05-29 02:01:47 +01:00
|
|
|
domainName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "local";
|
|
|
|
description = ''
|
|
|
|
Domain name for all advertisements.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
browseDomains = mkOption {
|
2016-09-07 12:21:45 +01:00
|
|
|
default = [ ];
|
|
|
|
example = [ "0pointer.de" "zeroconf.org" ];
|
2009-10-12 17:36:19 +01:00
|
|
|
description = ''
|
|
|
|
List of non-local DNS domains to be browsed.
|
|
|
|
'';
|
|
|
|
};
|
2008-03-06 17:11:22 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
ipv4 = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to use IPv4'';
|
|
|
|
};
|
2008-03-06 20:56:50 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
ipv6 = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to use IPv6'';
|
|
|
|
};
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2015-12-21 16:28:44 +00: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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-02-28 13:10:52 +00:00
|
|
|
allowPointToPoint = mkOption {
|
|
|
|
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. Use with care and YMMV!
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
wideArea = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable wide-area service discovery.'';
|
|
|
|
};
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2017-04-18 14:10:24 +01:00
|
|
|
reflector = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Reflect incoming mDNS requests to all allowed network interfaces.'';
|
|
|
|
};
|
|
|
|
|
2015-12-21 16:28:44 +00:00
|
|
|
publish = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to allow publishing in general.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
userServices = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to publish user services. Will set <literal>addresses=true</literal>.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
addresses = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to register mDNS address records for all local IP addresses.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hinfo = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to register an mDNS HINFO record which contains information about the
|
|
|
|
local operating system and CPU.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
workstation = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to register a service of type "_workstation._tcp" on the local LAN.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to announce the locally used domain name for browsing by other hosts.'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2008-03-06 17:11:22 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
nssmdns = mkOption {
|
|
|
|
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 19:20:50 +01:00
|
|
|
|
2017-07-12 13:23:15 +01:00
|
|
|
cacheEntriesMax = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
description = ''
|
|
|
|
Number of resource records to be cached per interface. Use 0 to
|
|
|
|
disable caching. Avahi daemon defaults to 4096 if not set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-07-28 10:48:08 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
Extra config to append to avahi-daemon.conf.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2012-06-08 15:29:31 +01:00
|
|
|
services.avahi.hostName = mkDefault config.networking.hostName;
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users = singleton
|
2009-10-12 17:36:19 +01:00
|
|
|
{ name = "avahi";
|
|
|
|
uid = config.ids.uids.avahi;
|
|
|
|
description = "`avahi-daemon' privilege separation user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups = singleton
|
2009-10-12 17:36:19 +01:00
|
|
|
{ name = "avahi";
|
|
|
|
gid = config.ids.gids.avahi;
|
|
|
|
};
|
|
|
|
|
|
|
|
system.nssModules = optional cfg.nssmdns pkgs.nssmdns;
|
|
|
|
|
2015-12-21 16:28:44 +00:00
|
|
|
environment.systemPackages = [ pkgs.avahi ];
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2016-10-15 21:30:50 +01:00
|
|
|
systemd.sockets.avahi-daemon =
|
|
|
|
{ description = "Avahi mDNS/DNS-SD Stack Activation Socket";
|
2018-12-19 21:39:20 +00:00
|
|
|
listenStreams = [ "/run/avahi-daemon/socket" ];
|
2016-10-15 21:30:50 +01:00
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
};
|
|
|
|
|
2015-12-21 16:28:44 +00:00
|
|
|
systemd.services.avahi-daemon =
|
2016-10-15 21:30:50 +01:00
|
|
|
{ description = "Avahi mDNS/DNS-SD Stack";
|
2016-09-11 07:13:04 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-10-15 21:30:50 +01:00
|
|
|
requires = [ "avahi-daemon.socket" ];
|
|
|
|
|
|
|
|
serviceConfig."NotifyAccess" = "main";
|
|
|
|
serviceConfig."BusName" = "org.freedesktop.Avahi";
|
|
|
|
serviceConfig."Type" = "dbus";
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2015-12-21 16:28:44 +00:00
|
|
|
path = [ pkgs.coreutils pkgs.avahi ];
|
|
|
|
|
2018-12-19 21:39:20 +00:00
|
|
|
preStart = "mkdir -p /run/avahi-daemon";
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
# Make NSS modules visible so that `avahi_nss_support ()' can
|
|
|
|
# return a sensible value.
|
|
|
|
export LD_LIBRARY_PATH="${config.system.nssModules.path}"
|
|
|
|
|
2015-12-21 16:28:44 +00:00
|
|
|
exec ${pkgs.avahi}/sbin/avahi-daemon --syslog -f "${avahiDaemonConf}"
|
2009-10-12 17:36:19 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.dbus.enable = true;
|
2015-12-21 16:28:44 +00:00
|
|
|
services.dbus.packages = [ pkgs.avahi ];
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2014-04-11 16:15:56 +01:00
|
|
|
# Enabling Avahi without exposing it in the firewall doesn't make
|
|
|
|
# sense.
|
|
|
|
networking.firewall.allowedUDPPorts = [ 5353 ];
|
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-11-23 01:29:25 +00:00
|
|
|
}
|