treewide: migrate nixos modules to networking.hosts

Signed-off-by: John Titor <50095635+JohnRTitor@users.noreply.github.com>
This commit is contained in:
John Titor 2025-06-04 20:55:03 +05:30 committed by Masum Reza
parent d859e3fcb9
commit cd64f1bd87
4 changed files with 27 additions and 27 deletions

View file

@ -3,15 +3,15 @@
let let
inherit (lib) inherit (lib)
attrNames attrNames
concatMap concatMapAttrs
concatMapStrings concatMapStrings
flip
forEach forEach
head head
listToAttrs listToAttrs
mkDefault mkDefault
mkOption mkOption
nameValuePair nameValuePair
optionalAttrs
optionalString optionalString
range range
toLower toLower
@ -91,23 +91,22 @@ let
# interfaces, use the IP address corresponding to # interfaces, use the IP address corresponding to
# the first interface (i.e. the first network in its # the first interface (i.e. the first network in its
# virtualisation.vlans option). # virtualisation.vlans option).
networking.extraHosts = flip concatMapStrings (attrNames nodes) ( networking.hosts = concatMapAttrs (
m': name: config:
let let
config = nodes.${m'};
hostnames = hostnames =
optionalString ( optionalString (
config.networking.domain != null config.networking.domain != null
) "${config.networking.hostName}.${config.networking.domain} " ) "${config.networking.hostName}.${config.networking.domain} "
+ "${config.networking.hostName}\n"; + "${config.networking.hostName}\n";
in in
optionalString ( optionalAttrs (config.networking.primaryIPAddress != "") {
config.networking.primaryIPAddress != "" "${config.networking.primaryIPAddress}" = [ hostnames ];
) "${config.networking.primaryIPAddress} ${hostnames}" }
+ optionalString (config.networking.primaryIPv6Address != "") ( // optionalAttrs (config.networking.primaryIPv6Address != "") {
"${config.networking.primaryIPv6Address} ${hostnames}" "${config.networking.primaryIPv6Address}" = [ hostnames ];
) }
); ) nodes;
virtualisation.qemu.options = qemuOptions; virtualisation.qemu.options = qemuOptions;
boot.initrd.services.udev.rules = concatMapStrings (x: x + "\n") udevRules; boot.initrd.services.udev.rules = concatMapStrings (x: x + "\n") udevRules;

View file

@ -365,9 +365,12 @@ in
keyFile = mkDefault key; keyFile = mkDefault key;
trustedCaFile = mkDefault caCert; trustedCaFile = mkDefault caCert;
}; };
networking.extraHosts = mkIf (config.services.etcd.enable) '' networking.hosts = mkIf (config.services.etcd.enable) {
127.0.0.1 etcd.${top.addons.dns.clusterDomain} etcd.local "127.0.0.1" = [
''; "etcd.${top.addons.dns.clusterDomain}"
"etcd.local"
];
};
services.flannel = with cfg.certs.flannelClient; { services.flannel = with cfg.certs.flannelClient; {
kubeconfig = top.lib.mkKubeConfig "flannel" { kubeconfig = top.lib.mkKubeConfig "flannel" {

View file

@ -70,10 +70,12 @@ in
# Rely on GCP's firewall instead # Rely on GCP's firewall instead
networking.firewall.enable = mkDefault false; networking.firewall.enable = mkDefault false;
# Configure default metadata hostnames networking.hosts = {
networking.extraHosts = '' "169.254.169.254" = [
169.254.169.254 metadata.google.internal metadata "metadata.google.internal"
''; "metadata"
];
};
networking.timeServers = [ "metadata.google.internal" ]; networking.timeServers = [ "metadata.google.internal" ];

View file

@ -1084,14 +1084,10 @@ in
) config.containers; ) config.containers;
# Generate /etc/hosts entries for the containers. # Generate /etc/hosts entries for the containers.
networking.extraHosts = concatStrings ( networking.hosts = lib.mapAttrs' (name: cfg: {
mapAttrsToList ( name = head (splitString "/" cfg.localAddress);
name: cfg: value = lib.optionals (cfg.localAddress != null) [ "${name}.containers" ];
optionalString (cfg.localAddress != null) '' }) config.containers;
${head (splitString "/" cfg.localAddress)} ${name}.containers
''
) config.containers
);
networking.dhcpcd.denyInterfaces = [ networking.dhcpcd.denyInterfaces = [
"ve-*" "ve-*"