Enable systemd's mymachines NSS module

It makes every local container registered with machined resolvable.

Changed files
+21 -23
nixos
modules
config
services
system
+20 -22
nixos/modules/config/nsswitch.nix
···
config = {
-
environment.etc =
-
[ # Name Service Switch configuration file. Required by the C library.
-
# !!! Factor out the mdns stuff. The avahi module should define
-
# an option used by this module.
-
{ source = pkgs.writeText "nsswitch.conf"
-
''
-
passwd: files ldap
-
group: files ldap
-
shadow: files ldap
-
hosts: files ${optionalString nssmdns "mdns_minimal [NOTFOUND=return]"} dns ${optionalString nssmdns "mdns"} ${optionalString nsswins "wins"} myhostname
-
networks: files dns
-
ethers: files
-
services: files
-
protocols: files
-
'';
-
target = "nsswitch.conf";
-
}
-
];
+
# Name Service Switch configuration file. Required by the C
+
# library. !!! Factor out the mdns stuff. The avahi module
+
# should define an option used by this module.
+
environment.etc."nsswitch.conf".text =
+
''
+
passwd: files ldap
+
group: files ldap
+
shadow: files ldap
+
hosts: files ${optionalString nssmdns "mdns_minimal [NOTFOUND=return]"} dns ${optionalString nssmdns "mdns"} ${optionalString nsswins "wins"} myhostname mymachines
+
networks: files dns
+
ethers: files
+
services: files
+
protocols: files
+
'';
-
# Use nss-myhostname to ensure that our hostname always resolves to
-
# a valid IP address. It returns all locally configured IP
-
# addresses, or ::1 and 127.0.0.2 as fallbacks.
-
system.nssModules = [ pkgs.systemd ];
+
# Systemd provides nss-myhostname to ensure that our hostname
+
# always resolves to a valid IP address. It returns all locally
+
# 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 ];
};
}
+1 -1
nixos/modules/services/system/nscd.nix
···
mkdir -m 0755 -p /var/db/nscd
'';
-
restartTriggers = [ config.environment.etc.hosts.source ];
+
restartTriggers = [ config.environment.etc.hosts.source config.environment.etc."nsswitch.conf".source ];
serviceConfig =
{ ExecStart = "@${pkgs.glibc}/sbin/nscd nscd -f ${cfgFile}";