1 # Configuration for the Name Service Switch (/etc/nsswitch.conf).
12 # Only works with nscd!
13 system.nssModules = lib.mkOption {
14 type = lib.types.listOf lib.types.path;
18 Search path for NSS (Name Service Switch) modules. This allows
19 several DNS resolution methods to be specified via
20 {file}`/etc/nsswitch.conf`.
24 path = lib.makeLibraryPath list;
28 system.nssDatabases = {
29 passwd = lib.mkOption {
30 type = lib.types.listOf lib.types.str;
32 List of passwd entries to configure in {file}`/etc/nsswitch.conf`.
34 Note that "files" is always prepended while "systemd" is appended if nscd is enabled.
36 This option only takes effect if nscd is enabled.
41 group = lib.mkOption {
42 type = lib.types.listOf lib.types.str;
44 List of group entries to configure in {file}`/etc/nsswitch.conf`.
46 Note that "files" is always prepended while "systemd" is appended if nscd is enabled.
48 This option only takes effect if nscd is enabled.
53 shadow = lib.mkOption {
54 type = lib.types.listOf lib.types.str;
56 List of shadow entries to configure in {file}`/etc/nsswitch.conf`.
58 Note that "files" is always prepended.
60 This option only takes effect if nscd is enabled.
65 sudoers = lib.mkOption {
66 type = lib.types.listOf lib.types.str;
68 List of sudoers entries to configure in {file}`/etc/nsswitch.conf`.
70 Note that "files" is always prepended.
72 This option only takes effect if nscd is enabled.
77 hosts = lib.mkOption {
78 type = lib.types.listOf lib.types.str;
80 List of hosts entries to configure in {file}`/etc/nsswitch.conf`.
82 Note that "files" is always prepended, and "dns" and "myhostname" are always appended.
84 This option only takes effect if nscd is enabled.
89 services = lib.mkOption {
90 type = lib.types.listOf lib.types.str;
92 List of services entries to configure in {file}`/etc/nsswitch.conf`.
94 Note that "files" is always prepended.
96 This option only takes effect if nscd is enabled.
104 (lib.mkRenamedOptionModule [ "system" "nssHosts" ] [ "system" "nssDatabases" "hosts" ])
110 assertion = config.system.nssModules.path != "" -> config.services.nscd.enable;
112 Loading NSS modules from system.nssModules (${config.system.nssModules.path}),
113 requires services.nscd.enable being set to true.
115 If disabling nscd is really necessary, it is possible to disable loading NSS modules
116 by setting `system.nssModules = lib.mkForce [];` in your configuration.nix.
121 # Name Service Switch configuration file. Required by the C
123 environment.etc."nsswitch.conf".text = ''
124 passwd: ${lib.concatStringsSep " " config.system.nssDatabases.passwd}
125 group: ${lib.concatStringsSep " " config.system.nssDatabases.group}
126 shadow: ${lib.concatStringsSep " " config.system.nssDatabases.shadow}
127 sudoers: ${lib.concatStringsSep " " config.system.nssDatabases.sudoers}
129 hosts: ${lib.concatStringsSep " " config.system.nssDatabases.hosts}
133 services: ${lib.concatStringsSep " " config.system.nssDatabases.services}
138 system.nssDatabases = {
139 passwd = lib.mkBefore [ "files" ];
140 group = lib.mkBefore [ "files" ];
141 shadow = lib.mkBefore [ "files" ];
142 sudoers = lib.mkBefore [ "files" ];
143 hosts = lib.mkMerge [
144 (lib.mkOrder 998 [ "files" ])
145 (lib.mkOrder 1499 [ "dns" ])
147 services = lib.mkBefore [ "files" ];