1 # Configuration for the Name Service Switch (/etc/nsswitch.conf).
2 { config, lib, pkgs, ... }:
7 # Only works with nscd!
8 system.nssModules = lib.mkOption {
9 type = lib.types.listOf lib.types.path;
13 Search path for NSS (Name Service Switch) modules. This allows
14 several DNS resolution methods to be specified via
15 {file}`/etc/nsswitch.conf`.
20 path = lib.makeLibraryPath list;
24 system.nssDatabases = {
25 passwd = lib.mkOption {
26 type = lib.types.listOf lib.types.str;
28 List of passwd entries to configure in {file}`/etc/nsswitch.conf`.
30 Note that "files" is always prepended while "systemd" is appended if nscd is enabled.
32 This option only takes effect if nscd is enabled.
37 group = lib.mkOption {
38 type = lib.types.listOf lib.types.str;
40 List of group entries to configure in {file}`/etc/nsswitch.conf`.
42 Note that "files" is always prepended while "systemd" is appended if nscd is enabled.
44 This option only takes effect if nscd is enabled.
49 shadow = lib.mkOption {
50 type = lib.types.listOf lib.types.str;
52 List of shadow entries to configure in {file}`/etc/nsswitch.conf`.
54 Note that "files" is always prepended.
56 This option only takes effect if nscd is enabled.
61 sudoers = lib.mkOption {
62 type = lib.types.listOf lib.types.str;
64 List of sudoers entries to configure in {file}`/etc/nsswitch.conf`.
66 Note that "files" is always prepended.
68 This option only takes effect if nscd is enabled.
73 hosts = lib.mkOption {
74 type = lib.types.listOf lib.types.str;
76 List of hosts entries to configure in {file}`/etc/nsswitch.conf`.
78 Note that "files" is always prepended, and "dns" and "myhostname" are always appended.
80 This option only takes effect if nscd is enabled.
85 services = lib.mkOption {
86 type = lib.types.listOf lib.types.str;
88 List of services entries to configure in {file}`/etc/nsswitch.conf`.
90 Note that "files" is always prepended.
92 This option only takes effect if nscd is enabled.
100 (lib.mkRenamedOptionModule [ "system" "nssHosts" ] [ "system" "nssDatabases" "hosts" ])
106 assertion = config.system.nssModules.path != "" -> config.services.nscd.enable;
108 Loading NSS modules from system.nssModules (${config.system.nssModules.path}),
109 requires services.nscd.enable being set to true.
111 If disabling nscd is really necessary, it is possible to disable loading NSS modules
112 by setting `system.nssModules = lib.mkForce [];` in your configuration.nix.
117 # Name Service Switch configuration file. Required by the C
119 environment.etc."nsswitch.conf".text = ''
120 passwd: ${lib.concatStringsSep " " config.system.nssDatabases.passwd}
121 group: ${lib.concatStringsSep " " config.system.nssDatabases.group}
122 shadow: ${lib.concatStringsSep " " config.system.nssDatabases.shadow}
123 sudoers: ${lib.concatStringsSep " " config.system.nssDatabases.sudoers}
125 hosts: ${lib.concatStringsSep " " config.system.nssDatabases.hosts}
129 services: ${lib.concatStringsSep " " config.system.nssDatabases.services}
134 system.nssDatabases = {
135 passwd = lib.mkBefore [ "files" ];
136 group = lib.mkBefore [ "files" ];
137 shadow = lib.mkBefore [ "files" ];
138 sudoers = lib.mkBefore [ "files" ];
139 hosts = lib.mkMerge [
140 (lib.mkOrder 998 [ "files" ])
141 (lib.mkOrder 1499 [ "dns" ])
143 services = lib.mkBefore [ "files" ];