2008-11-23 02:28:58 +01:00
|
|
|
# Avahi daemon.
|
2015-12-21 17:28:44 +01:00
|
|
|
{ config, lib, utils, 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
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
cfg = config.services.avahi;
|
|
|
|
|
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.
|
|
|
|
if hostName != ""
|
|
|
|
then "host-name=${hostName}"
|
|
|
|
else ""}
|
2009-10-12 18:36:19 +02:00
|
|
|
browse-domains=${concatStringsSep ", " browseDomains}
|
2008-03-06 18:11:22 +01:00
|
|
|
use-ipv4=${if ipv4 then "yes" else "no"}
|
|
|
|
use-ipv6=${if ipv6 then "yes" else "no"}
|
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}"}
|
2008-03-06 18:11:22 +01:00
|
|
|
|
|
|
|
[wide-area]
|
|
|
|
enable-wide-area=${if wideArea then "yes" else "no"}
|
|
|
|
|
|
|
|
[publish]
|
2015-12-21 17:28:44 +01:00
|
|
|
disable-publishing=${if publish.enable then "no" else "yes"}
|
|
|
|
disable-user-service-publishing=${if publish.userServices then "no" else "yes"}
|
|
|
|
publish-addresses=${if publish.userServices || publish.addresses then "yes" else "no"}
|
|
|
|
publish-hinfo=${if publish.hinfo then "yes" else "no"}
|
|
|
|
publish-workstation=${if publish.workstation then "yes" else "no"}
|
|
|
|
publish-domain=${if publish.domain then "yes" else "no"}
|
2008-03-06 18:11:22 +01:00
|
|
|
'';
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
{
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### interface
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02: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 14:27:35 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
hostName = mkOption {
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-12-07 12:03:50 +01:00
|
|
|
description = ''
|
|
|
|
Host name advertised on the LAN. If not set, avahi will use the value
|
|
|
|
of config.networking.hostName.
|
|
|
|
'';
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-07-01 14:27:35 +02:00
|
|
|
|
2016-05-29 03:01:47 +02:00
|
|
|
domainName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "local";
|
|
|
|
description = ''
|
|
|
|
Domain name for all advertisements.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
browseDomains = mkOption {
|
2016-09-07 13:21:45 +02:00
|
|
|
default = [ ];
|
|
|
|
example = [ "0pointer.de" "zeroconf.org" ];
|
2009-10-12 18:36:19 +02:00
|
|
|
description = ''
|
|
|
|
List of non-local DNS domains to be browsed.
|
|
|
|
'';
|
|
|
|
};
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
ipv4 = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to use IPv4'';
|
|
|
|
};
|
2008-03-06 21:56:50 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
ipv6 = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to use IPv6'';
|
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2015-12-21 17:28:44 +01: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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
wideArea = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable wide-area service discovery.'';
|
|
|
|
};
|
2008-11-23 02:28:58 +01:00
|
|
|
|
2015-12-21 17:28:44 +01: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 18:36:19 +02:00
|
|
|
};
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2009-10-12 18:36:19 +02: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 20:20:50 +02:00
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2012-06-08 16:29:31 +02:00
|
|
|
services.avahi.hostName = mkDefault config.networking.hostName;
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "avahi";
|
|
|
|
uid = config.ids.uids.avahi;
|
|
|
|
description = "`avahi-daemon' privilege separation user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "avahi";
|
|
|
|
gid = config.ids.gids.avahi;
|
|
|
|
};
|
|
|
|
|
|
|
|
system.nssModules = optional cfg.nssmdns pkgs.nssmdns;
|
|
|
|
|
2015-12-21 17:28:44 +01:00
|
|
|
environment.systemPackages = [ pkgs.avahi ];
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2016-10-15 22:30:50 +02:00
|
|
|
systemd.sockets.avahi-daemon =
|
|
|
|
{ description = "Avahi mDNS/DNS-SD Stack Activation Socket";
|
|
|
|
listenStreams = [ "/var/run/avahi-daemon/socket" ];
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
};
|
|
|
|
|
2015-12-21 17:28:44 +01:00
|
|
|
systemd.services.avahi-daemon =
|
2016-10-15 22:30:50 +02:00
|
|
|
{ description = "Avahi mDNS/DNS-SD Stack";
|
2016-09-11 08:13:04 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-10-15 22:30:50 +02:00
|
|
|
requires = [ "avahi-daemon.socket" ];
|
|
|
|
|
|
|
|
serviceConfig."NotifyAccess" = "main";
|
|
|
|
serviceConfig."BusName" = "org.freedesktop.Avahi";
|
|
|
|
serviceConfig."Type" = "dbus";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2015-12-21 17:28:44 +01:00
|
|
|
path = [ pkgs.coreutils pkgs.avahi ];
|
|
|
|
|
|
|
|
preStart = "mkdir -p /var/run/avahi-daemon";
|
2009-10-12 18:36:19 +02: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 17:28:44 +01:00
|
|
|
exec ${pkgs.avahi}/sbin/avahi-daemon --syslog -f "${avahiDaemonConf}"
|
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
|
|
|
|
2014-04-11 17:15:56 +02:00
|
|
|
# Enabling Avahi without exposing it in the firewall doesn't make
|
|
|
|
# sense.
|
|
|
|
networking.firewall.allowedUDPPorts = [ 5353 ];
|
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-11-23 02:29:25 +01:00
|
|
|
}
|