From d1f29d328d16885187579c575d4ba1f3059d6094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Mon, 17 Mar 2008 13:58:57 +0000 Subject: [PATCH] Add support for `nss-mdns'. Currently, the solution is a bit hackish since running applications will not work after a `nixos-rebuild' because `libnss_mdns' is not in their `LD_LIBRARY_PATH'. svn path=/nixos/trunk/; revision=11162 --- etc/default.nix | 8 +++++--- etc/nsswitch-mdns.conf | 11 +++++++++++ etc/profile.sh | 1 + system/options.nix | 15 +++++++++++++++ system/system.nix | 7 +++++-- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 etc/nsswitch-mdns.conf diff --git a/etc/default.nix b/etc/default.nix index 244f32fb5df..e8b44f553b9 100644 --- a/etc/default.nix +++ b/etc/default.nix @@ -1,5 +1,5 @@ { config, pkgs, upstartJobs, systemPath, wrapperDir -, defaultShell, extraEtc, nixEnvVars, modulesTree +, defaultShell, extraEtc, nixEnvVars, modulesTree, nssModulesPath }: let @@ -56,7 +56,9 @@ import ../helpers/make-etc.nix { } { # Name Service Switch configuration file. Required by the C library. - source = ./nsswitch.conf; + source = if config.services.avahi.nssmdns + then (assert config.services.avahi.enable; ./nsswitch-mdns.conf) + else ./nsswitch.conf; target = "nsswitch.conf"; } @@ -116,7 +118,7 @@ import ../helpers/make-etc.nix { { # Script executed when the shell starts as a login shell. source = pkgs.substituteAll { src = ./profile.sh; - inherit systemPath wrapperDir modulesTree; + inherit systemPath wrapperDir modulesTree nssModulesPath; inherit (pkgs) glibc; timeZone = config.time.timeZone; defaultLocale = config.i18n.defaultLocale; diff --git a/etc/nsswitch-mdns.conf b/etc/nsswitch-mdns.conf new file mode 100644 index 00000000000..eefbd0c4203 --- /dev/null +++ b/etc/nsswitch-mdns.conf @@ -0,0 +1,11 @@ +# NSS configuration files with mDNS enabled (requires running Avahi daemon). + +passwd: ldap files +group: ldap files +shadow: ldap files + +hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 +networks: files dns + +services: files +protocols: files diff --git a/etc/profile.sh b/etc/profile.sh index 9f98d4f7461..2aed1f949f4 100644 --- a/etc/profile.sh +++ b/etc/profile.sh @@ -1,4 +1,5 @@ export PATH=@wrapperDir@:/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin +export LD_LIBRARY_PATH=@nssModulesPath@ export MODULE_DIR=@modulesTree@/lib/modules export NIXPKGS_CONFIG=/nix/etc/config.nix export PAGER="less -R" diff --git a/system/options.nix b/system/options.nix index 409cbba3906..0d4d9e01257 100644 --- a/system/options.nix +++ b/system/options.nix @@ -986,6 +986,21 @@ 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. + ''; + }; }; bitlbee = { diff --git a/system/system.nix b/system/system.nix index 24806222772..3843b484a2e 100644 --- a/system/system.nix +++ b/system/system.nix @@ -125,7 +125,8 @@ rec { # NSS modules. Hacky! nssModules = - if config.users.ldap.enable then [pkgs.nss_ldap] else []; + pkgs.lib.optional config.users.ldap.enable pkgs.nss_ldap + ++ pkgs.lib.optional config.services.avahi.nssmdns pkgs.nssmdns; nssModulesPath = pkgs.lib.concatStrings (pkgs.lib.intersperse ":" (map (mod: mod + "/lib") nssModules)); @@ -175,7 +176,7 @@ rec { # The static parts of /etc. etc = import ../etc/default.nix { inherit config pkgs upstartJobs systemPath wrapperDir - defaultShell nixEnvVars modulesTree; + defaultShell nixEnvVars modulesTree nssModulesPath; extraEtc = pkgs.lib.concatLists (map (job: job.extraEtc) upstartJobs.jobs); }; @@ -255,6 +256,8 @@ rec { ] ++ pkgs.lib.optional config.security.sudo.enable pkgs.sudo ++ pkgs.lib.optional config.services.bitlbee.enable pkgs.bitlbee + ++ pkgs.lib.optional config.services.avahi.enable pkgs.avahi + ++ pkgs.lib.optional config.services.avahi.nssmdns pkgs.nssmdns ++ pkgs.lib.optional config.networking.defaultMailServer.directDelivery pkgs.ssmtp ++ pkgs.lib.concatLists (map (job: job.extraPath) upstartJobs.jobs) ++ config.environment.extraPackages pkgs