2008-11-23 01:28:58 +00:00
|
|
|
# Avahi daemon.
|
2009-10-12 16:36:19 +00:00
|
|
|
{ config, pkgs, ... }:
|
2008-03-06 17:11:22 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
with pkgs.lib;
|
2008-11-23 01:28:58 +00:00
|
|
|
|
|
|
|
let
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
cfg = config.services.avahi;
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
inherit (pkgs) avahi;
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
avahiDaemonConf = with cfg; pkgs.writeText "avahi-daemon.conf" ''
|
2008-03-06 17:11:22 +00:00
|
|
|
[server]
|
2012-09-07 08:58:53 +00: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 16:36:19 +00:00
|
|
|
browse-domains=${concatStringsSep ", " browseDomains}
|
2008-03-06 17:11:22 +00:00
|
|
|
use-ipv4=${if ipv4 then "yes" else "no"}
|
|
|
|
use-ipv6=${if ipv6 then "yes" else "no"}
|
|
|
|
|
|
|
|
[wide-area]
|
|
|
|
enable-wide-area=${if wideArea then "yes" else "no"}
|
|
|
|
|
|
|
|
[publish]
|
|
|
|
disable-publishing=${if publishing then "no" else "yes"}
|
|
|
|
'';
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
in
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
{
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### interface
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00: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 12:27:35 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
hostName = mkOption {
|
2012-06-08 14:29:31 +00:00
|
|
|
type = types.uniq types.string;
|
2009-10-12 16:36:19 +00:00
|
|
|
description = ''Host name advertised on the LAN.'';
|
|
|
|
};
|
2009-07-01 12:27:35 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
browseDomains = mkOption {
|
|
|
|
default = [ "0pointer.de" "zeroconf.org" ];
|
|
|
|
description = ''
|
|
|
|
List of non-local DNS domains to be browsed.
|
|
|
|
'';
|
|
|
|
};
|
2008-03-06 17:11:22 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
ipv4 = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to use IPv4'';
|
|
|
|
};
|
2008-03-06 20:56:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
ipv6 = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to use IPv6'';
|
|
|
|
};
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
wideArea = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable wide-area service discovery.'';
|
|
|
|
};
|
2008-11-23 01:28:58 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
publishing = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to allow publishing.'';
|
|
|
|
};
|
2008-03-06 17:11:22 +00:00
|
|
|
|
2009-10-12 16:36:19 +00: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 18:20:50 +00:00
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2012-06-08 14:29:31 +00:00
|
|
|
services.avahi.hostName = mkDefault config.networking.hostName;
|
|
|
|
|
2009-10-12 16:36:19 +00: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;
|
|
|
|
|
|
|
|
environment.systemPackages = [ avahi ];
|
|
|
|
|
2009-10-12 18:09:34 +00:00
|
|
|
jobs.avahi_daemon =
|
2009-10-12 16:36:19 +00:00
|
|
|
{ name = "avahi-daemon";
|
|
|
|
|
2009-12-15 13:02:23 +00:00
|
|
|
startOn = "ip-up";
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
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}"
|
|
|
|
|
2010-05-08 22:28:26 +00:00
|
|
|
mkdir -p /var/run/avahi-daemon
|
|
|
|
|
2010-10-05 15:17:09 +00:00
|
|
|
exec ${avahi}/sbin/avahi-daemon --syslog -f "${avahiDaemonConf}"
|
2009-10-12 16:36:19 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.dbus.enable = true;
|
|
|
|
services.dbus.packages = [avahi];
|
|
|
|
|
2008-11-23 01:28:58 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2008-11-23 01:29:25 +00:00
|
|
|
}
|