2008-11-23 02:28:58 +01:00
|
|
|
# Avahi daemon.
|
2008-12-04 16:48:27 +01:00
|
|
|
{pkgs, config, ...}:
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
###### interface
|
2008-03-06 18:11:22 +01:00
|
|
|
let
|
2008-11-23 02:28:58 +01:00
|
|
|
inherit (pkgs.lib) mkOption;
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
options = {
|
|
|
|
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').
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hostName = mkOption {
|
|
|
|
default = "nixos"; # XXX: Would be nice to use `networking.hostName'.
|
|
|
|
description = ''Host name advertised on the LAN.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
browseDomains = mkOption {
|
|
|
|
default = [ "0pointer.de" "zeroconf.org" ];
|
|
|
|
description = ''
|
|
|
|
List of non-local DNS domains to be browsed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ipv4 = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to use IPv4'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ipv6 = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''Whether to use IPv6'';
|
|
|
|
};
|
|
|
|
|
|
|
|
wideArea = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to enable wide-area service discovery.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
publishing = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''Whether to allow publishing.'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Warning: Currently, enabling this option breaks DNS lookups after
|
|
|
|
a `nixos-rebuild'. This is because `/etc/nsswitch.conf' is
|
|
|
|
updated to use `nss-mdns' but `libnss_mdns' is not in
|
|
|
|
applications' `LD_LIBRARY_PATH'. The next time `/etc/profile' is
|
|
|
|
sourced, it will set up an appropriate `LD_LIBRARY_PATH', though.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
let
|
|
|
|
cfg = config.services.avahi;
|
2008-11-23 02:29:25 +01:00
|
|
|
inherit (pkgs.lib) mkIf mkThenElse;
|
2008-11-23 02:28:58 +01:00
|
|
|
|
|
|
|
inherit (pkgs) avahi writeText lib;
|
|
|
|
|
|
|
|
avahiDaemonConf = with cfg; writeText "avahi-daemon.conf" ''
|
2008-03-06 18:11:22 +01:00
|
|
|
[server]
|
|
|
|
host-name=${hostName}
|
|
|
|
browse-domains=${lib.concatStringsSep ", " browseDomains}
|
|
|
|
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"}
|
|
|
|
'';
|
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
user = {
|
|
|
|
name = "avahi";
|
2009-05-29 16:25:56 +02:00
|
|
|
uid = config.ids.uids.avahi;
|
2008-11-23 02:28:58 +01:00
|
|
|
description = "`avahi-daemon' privilege separation user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = {
|
|
|
|
name = "avahi";
|
2009-05-29 16:25:56 +02:00
|
|
|
gid = config.ids.gids.avahi;
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
job = {
|
|
|
|
name = "avahi-daemon";
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
|
|
|
respawn
|
|
|
|
script
|
|
|
|
export PATH="${avahi}/bin:${avahi}/sbin:$PATH"
|
2009-07-01 14:27:35 +02:00
|
|
|
|
|
|
|
# Make NSS modules visible so that `avahi_nss_support ()' can
|
|
|
|
# return a sensible value.
|
|
|
|
export LD_LIBRARY_PATH="${config.system.nssModules.path}"
|
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
exec ${avahi}/sbin/avahi-daemon --daemonize -f "${avahiDaemonConf}"
|
|
|
|
end script
|
|
|
|
'';
|
|
|
|
};
|
2008-03-06 18:11:22 +01:00
|
|
|
in
|
|
|
|
|
2008-11-23 02:29:25 +01:00
|
|
|
mkIf cfg.enable {
|
2008-11-23 02:28:58 +01:00
|
|
|
require = [
|
2009-05-25 01:13:23 +02:00
|
|
|
# ../upstart-jobs/default.nix # config.services.extraJobs
|
2009-05-20 01:14:45 +02:00
|
|
|
# ../system/? # system.nssModules
|
|
|
|
# ? # config.environment.etc
|
|
|
|
# ../system/user.nix # users.*
|
|
|
|
# ../upstart-jobs/udev.nix # services.udev.*
|
2009-05-25 01:13:23 +02:00
|
|
|
# ../upstart-jobs/dbus.nix # services.dbus.*
|
2009-05-20 01:14:45 +02:00
|
|
|
# ? # config.environment.extraPackages
|
2008-11-23 02:28:58 +01:00
|
|
|
options
|
2008-03-06 18:11:22 +01:00
|
|
|
];
|
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
system = {
|
2008-11-23 02:29:25 +01:00
|
|
|
nssModules = pkgs.lib.optional cfg.nssmdns pkgs.nssmdns;
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
2008-03-06 21:56:50 +01:00
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
environment = {
|
2008-11-23 02:29:25 +01:00
|
|
|
extraPackages = [avahi];
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
2008-11-23 02:29:25 +01:00
|
|
|
extraUsers = [user];
|
|
|
|
extraGroups = [group];
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services = {
|
2008-11-23 02:29:25 +01:00
|
|
|
extraJobs = [job];
|
2008-03-06 18:11:22 +01:00
|
|
|
|
2008-11-23 02:28:58 +01:00
|
|
|
dbus = {
|
2008-11-23 02:29:25 +01:00
|
|
|
enable = true;
|
|
|
|
services = [avahi];
|
2008-11-23 02:28:58 +01:00
|
|
|
};
|
|
|
|
};
|
2008-11-23 02:29:25 +01:00
|
|
|
}
|