Generate nsswitch.conf properly

This commit is contained in:
Eelco Dolstra 2012-10-06 20:58:46 -04:00
parent 4b78161e3e
commit 757ab7f6d3
3 changed files with 22 additions and 32 deletions

View file

@ -1,11 +0,0 @@
# NSS configuration files with mDNS enabled (requires running Avahi daemon).
passwd: ldap files
group: ldap files
shadow: ldap files
hosts: files mdns_minimal [NOTFOUND=return] dns mdns
networks: files dns
services: files
protocols: files

View file

@ -1,10 +0,0 @@
passwd: files ldap
group: files ldap
shadow: files ldap
hosts: files dns
networks: files dns
ethers: files
services: files
protocols: files

View file

@ -1,13 +1,15 @@
# Configuration for the Name Service Switch (/etc/nsswitch.conf). # Configuration for the Name Service Switch (/etc/nsswitch.conf).
{config, pkgs, ...}: { config, pkgs, ... }:
with pkgs.lib;
let let
options = { options = {
# NSS modules. Hacky! # NSS modules. Hacky!
system.nssModules = pkgs.lib.mkOption { system.nssModules = mkOption {
internal = true; internal = true;
default = []; default = [];
description = " description = "
@ -15,34 +17,43 @@ let
several DNS resolution methods to be specified via several DNS resolution methods to be specified via
<filename>/etc/nsswitch.conf</filename>. <filename>/etc/nsswitch.conf</filename>.
"; ";
merge = pkgs.lib.mergeListOption; merge = mergeListOption;
apply = list: apply = list:
let let
list2 = list2 =
list list
# !!! this should be in the LDAP module # !!! this should be in the LDAP module
++ pkgs.lib.optional config.users.ldap.enable pkgs.nss_ldap; ++ optional config.users.ldap.enable pkgs.nss_ldap;
in { in {
list = list2; list = list2;
path = pkgs.lib.makeLibraryPath list2; path = makeLibraryPath list2;
}; };
}; };
}; };
inherit (config.services.avahi) nssmdns;
in in
{ {
require = [options]; require = [ options ];
environment.etc = environment.etc =
[ # Name Service Switch configuration file. Required by the C library. [ # Name Service Switch configuration file. Required by the C library.
# !!! Factor out the mdns stuff. The avahi module should define # !!! Factor out the mdns stuff. The avahi module should define
# an option used by this module. # an option used by this module.
{ source = { source = pkgs.writeText "nsswitch.conf"
if config.services.avahi.nssmdns ''
then ./nsswitch-mdns.conf passwd: files ldap
else ./nsswitch.conf; group: files ldap
shadow: files ldap
hosts: files ${optionalString nssmdns "mdns_minimal [NOTFOUND=return]"} dns ${optionalString nssmdns "mdns"}
networks: files dns
ethers: files
services: files
protocols: files
'';
target = "nsswitch.conf"; target = "nsswitch.conf";
} }
]; ];
@ -58,5 +69,5 @@ in
# chroot gets to seem them, and (ii) applications can benefit from # chroot gets to seem them, and (ii) applications can benefit from
# changes in the list of NSS modules at run-time, without requiring # changes in the list of NSS modules at run-time, without requiring
# a reboot. # a reboot.
environment.systemPackages = [config.system.nssModules.list]; environment.systemPackages = [ config.system.nssModules.list ];
} }