From 63fa3e7c6209dacc00b465614acae303839b68ff Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Thu, 29 Jun 2017 15:32:47 +0200 Subject: nsswitch: fix typo specifying nss-resolve module this had the effect of not being able to load nss-resolve and falling back to dns module in all cases. --- nixos/modules/config/nsswitch.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nixos') diff --git a/nixos/modules/config/nsswitch.nix b/nixos/modules/config/nsswitch.nix index d541fff140eb..16a0bfb5693d 100644 --- a/nixos/modules/config/nsswitch.nix +++ b/nixos/modules/config/nsswitch.nix @@ -15,7 +15,7 @@ let hostArray = [ "files" "mymachines" ] ++ optionals nssmdns [ "mdns_minimal [!UNAVAIL=return]" ] ++ optionals nsswins [ "wins" ] - ++ optionals resolved ["resolv [!UNAVAIL=return]"] + ++ optionals resolved ["resolve [!UNAVAIL=return]"] ++ [ "dns" ] ++ optionals nssmdns [ "mdns" ] ++ ["myhostname" ]; -- cgit 1.4.1 From 7410b0c82c2fe57460d5ad3f1b2e1476d7b39c43 Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Fri, 30 Jun 2017 02:20:09 +0200 Subject: nsswitch: add assertions for enabled nscd --- nixos/modules/config/nsswitch.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'nixos') diff --git a/nixos/modules/config/nsswitch.nix b/nixos/modules/config/nsswitch.nix index 16a0bfb5693d..52d9944a3f2e 100644 --- a/nixos/modules/config/nsswitch.nix +++ b/nixos/modules/config/nsswitch.nix @@ -11,6 +11,8 @@ let ldap = (config.users.ldap.enable && config.users.ldap.nsswitch); sssd = config.services.sssd.enable; resolved = config.services.resolved.enable; + # only with nscd up and running we can load NSS modules that are not integrated in NSS + canLoadExternalModules = config.services.nscd.enable; hostArray = [ "files" "mymachines" ] ++ optionals nssmdns [ "mdns_minimal [!UNAVAIL=return]" ] @@ -36,6 +38,7 @@ in { options = { # NSS modules. Hacky! + # Only works with nscd! system.nssModules = mkOption { type = types.listOf types.path; internal = true; @@ -55,6 +58,18 @@ in { }; config = { + assertions = [ + { + # generic catch if the NixOS module adding to nssModules does not prevent it with specific message. + assertion = config.system.nssModules.path != "" -> canLoadExternalModules; + message = "Loading NSS modules from path ${config.system.nssModules.path} requires nscd being enabled."; + } + { + # resolved does not need to add to nssModules, therefore needs an extra assertion + assertion = resolved -> canLoadExternalModules; + message = "Loading systemd-resolved's nss-resolve NSS module requires nscd being enabled."; + } + ]; # Name Service Switch configuration file. Required by the C # library. !!! Factor out the mdns stuff. The avahi module @@ -78,7 +93,7 @@ in { # configured IP addresses, or ::1 and 127.0.0.2 as # fallbacks. Systemd also provides nss-mymachines to return IP # addresses of local containers. - system.nssModules = [ config.systemd.package.out ]; + system.nssModules = optionals canLoadExternalModules [ config.systemd.package.out ]; }; } -- cgit 1.4.1 From e370e97f3dab410ac460af3cb9974b8df7b3214d Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Fri, 30 Jun 2017 02:20:50 +0200 Subject: nsswitch: only add modules to nsswitch.conf if they can be loaded --- nixos/modules/config/nsswitch.nix | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'nixos') diff --git a/nixos/modules/config/nsswitch.nix b/nixos/modules/config/nsswitch.nix index 52d9944a3f2e..16c43a99ad56 100644 --- a/nixos/modules/config/nsswitch.nix +++ b/nixos/modules/config/nsswitch.nix @@ -6,26 +6,29 @@ with lib; let - inherit (config.services.avahi) nssmdns; - inherit (config.services.samba) nsswins; - ldap = (config.users.ldap.enable && config.users.ldap.nsswitch); - sssd = config.services.sssd.enable; - resolved = config.services.resolved.enable; # only with nscd up and running we can load NSS modules that are not integrated in NSS canLoadExternalModules = config.services.nscd.enable; - - hostArray = [ "files" "mymachines" ] + myhostname = canLoadExternalModules; + mymachines = canLoadExternalModules; + nssmdns = canLoadExternalModules && config.services.avahi.nssmdns; + nsswins = canLoadExternalModules && config.services.samba.nsswins; + ldap = canLoadExternalModules && (config.users.ldap.enable && config.users.ldap.nsswitch); + sssd = canLoadExternalModules && config.services.sssd.enable; + resolved = canLoadExternalModules && config.services.resolved.enable; + + hostArray = [ "files" ] + ++ optionals mymachines [ "mymachines" ] ++ optionals nssmdns [ "mdns_minimal [!UNAVAIL=return]" ] ++ optionals nsswins [ "wins" ] ++ optionals resolved ["resolve [!UNAVAIL=return]"] ++ [ "dns" ] ++ optionals nssmdns [ "mdns" ] - ++ ["myhostname" ]; + ++ optionals myhostname ["myhostname" ]; passwdArray = [ "files" ] ++ optional sssd "sss" ++ optionals ldap [ "ldap" ] - ++ [ "mymachines" ]; + ++ optionals mymachines [ "mymachines" ]; shadowArray = [ "files" ] ++ optional sssd "sss" -- cgit 1.4.1