2020-04-24 23:36:52 +00:00
|
|
|
# Configuration for the Name Service Switch (/etc/nsswitch.conf).
|
|
|
|
{ config, lib, pkgs, ... }:
|
2020-05-15 21:57:56 +00:00
|
|
|
{
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
# NSS modules. Hacky!
|
|
|
|
# Only works with nscd!
|
2024-09-19 14:19:46 +00:00
|
|
|
system.nssModules = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.path;
|
2020-04-24 23:36:52 +00:00
|
|
|
internal = true;
|
2024-06-05 15:53:02 +00:00
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Search path for NSS (Name Service Switch) modules. This allows
|
|
|
|
several DNS resolution methods to be specified via
|
2022-08-12 12:06:08 +00:00
|
|
|
{file}`/etc/nsswitch.conf`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
apply = list:
|
|
|
|
{
|
|
|
|
inherit list;
|
2024-09-19 14:19:46 +00:00
|
|
|
path = lib.makeLibraryPath list;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-05-03 17:38:23 +00:00
|
|
|
system.nssDatabases = {
|
2024-09-19 14:19:46 +00:00
|
|
|
passwd = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
List of passwd entries to configure in {file}`/etc/nsswitch.conf`.
|
2020-05-03 17:38:23 +00:00
|
|
|
|
|
|
|
Note that "files" is always prepended while "systemd" is appended if nscd is enabled.
|
|
|
|
|
|
|
|
This option only takes effect if nscd is enabled.
|
|
|
|
'';
|
2024-06-05 15:53:02 +00:00
|
|
|
default = [ ];
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
group = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
List of group entries to configure in {file}`/etc/nsswitch.conf`.
|
2020-05-03 17:38:23 +00:00
|
|
|
|
|
|
|
Note that "files" is always prepended while "systemd" is appended if nscd is enabled.
|
|
|
|
|
|
|
|
This option only takes effect if nscd is enabled.
|
|
|
|
'';
|
2024-06-05 15:53:02 +00:00
|
|
|
default = [ ];
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
shadow = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
List of shadow entries to configure in {file}`/etc/nsswitch.conf`.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-05-03 17:38:23 +00:00
|
|
|
Note that "files" is always prepended.
|
|
|
|
|
|
|
|
This option only takes effect if nscd is enabled.
|
|
|
|
'';
|
2024-06-05 15:53:02 +00:00
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
sudoers = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-06-05 15:53:02 +00:00
|
|
|
description = ''
|
|
|
|
List of sudoers entries to configure in {file}`/etc/nsswitch.conf`.
|
|
|
|
|
|
|
|
Note that "files" is always prepended.
|
|
|
|
|
|
|
|
This option only takes effect if nscd is enabled.
|
|
|
|
'';
|
|
|
|
default = [ ];
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
hosts = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
List of hosts entries to configure in {file}`/etc/nsswitch.conf`.
|
2020-05-03 17:38:23 +00:00
|
|
|
|
|
|
|
Note that "files" is always prepended, and "dns" and "myhostname" are always appended.
|
|
|
|
|
|
|
|
This option only takes effect if nscd is enabled.
|
|
|
|
'';
|
2024-06-05 15:53:02 +00:00
|
|
|
default = [ ];
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
services = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
List of services entries to configure in {file}`/etc/nsswitch.conf`.
|
2020-05-03 17:38:23 +00:00
|
|
|
|
|
|
|
Note that "files" is always prepended.
|
|
|
|
|
|
|
|
This option only takes effect if nscd is enabled.
|
|
|
|
'';
|
2024-06-05 15:53:02 +00:00
|
|
|
default = [ ];
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-05-03 17:38:23 +00:00
|
|
|
imports = [
|
2024-09-19 14:19:46 +00:00
|
|
|
(lib.mkRenamedOptionModule [ "system" "nssHosts" ] [ "system" "nssDatabases" "hosts" ])
|
2020-05-03 17:38:23 +00:00
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
config = {
|
|
|
|
assertions = [
|
|
|
|
{
|
2020-05-15 21:57:56 +00:00
|
|
|
assertion = config.system.nssModules.path != "" -> config.services.nscd.enable;
|
2022-04-27 09:35:20 +00:00
|
|
|
message = ''
|
|
|
|
Loading NSS modules from system.nssModules (${config.system.nssModules.path}),
|
|
|
|
requires services.nscd.enable being set to true.
|
|
|
|
|
|
|
|
If disabling nscd is really necessary, it is possible to disable loading NSS modules
|
|
|
|
by setting `system.nssModules = lib.mkForce [];` in your configuration.nix.
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# Name Service Switch configuration file. Required by the C
|
2020-05-03 17:38:23 +00:00
|
|
|
# library.
|
2020-04-24 23:36:52 +00:00
|
|
|
environment.etc."nsswitch.conf".text = ''
|
2024-09-19 14:19:46 +00:00
|
|
|
passwd: ${lib.concatStringsSep " " config.system.nssDatabases.passwd}
|
|
|
|
group: ${lib.concatStringsSep " " config.system.nssDatabases.group}
|
|
|
|
shadow: ${lib.concatStringsSep " " config.system.nssDatabases.shadow}
|
|
|
|
sudoers: ${lib.concatStringsSep " " config.system.nssDatabases.sudoers}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
hosts: ${lib.concatStringsSep " " config.system.nssDatabases.hosts}
|
2020-04-24 23:36:52 +00:00
|
|
|
networks: files
|
|
|
|
|
|
|
|
ethers: files
|
2024-09-19 14:19:46 +00:00
|
|
|
services: ${lib.concatStringsSep " " config.system.nssDatabases.services}
|
2020-04-24 23:36:52 +00:00
|
|
|
protocols: files
|
|
|
|
rpc: files
|
|
|
|
'';
|
|
|
|
|
2020-05-03 17:38:23 +00:00
|
|
|
system.nssDatabases = {
|
2024-09-19 14:19:46 +00:00
|
|
|
passwd = lib.mkBefore [ "files" ];
|
|
|
|
group = lib.mkBefore [ "files" ];
|
|
|
|
shadow = lib.mkBefore [ "files" ];
|
|
|
|
sudoers = lib.mkBefore [ "files" ];
|
|
|
|
hosts = lib.mkMerge [
|
|
|
|
(lib.mkOrder 998 [ "files" ])
|
|
|
|
(lib.mkOrder 1499 [ "dns" ])
|
2020-05-15 21:57:56 +00:00
|
|
|
];
|
2024-09-19 14:19:46 +00:00
|
|
|
services = lib.mkBefore [ "files" ];
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|