Revert "treewide: migrate nixos modules to networking.hosts" (#415085)

This commit is contained in:
Vladimír Čunát 2025-06-08 21:34:22 +02:00
commit 0fc422d6c3
No known key found for this signature in database
GPG key ID: E747DF1F9575A3AA
4 changed files with 31 additions and 34 deletions

View file

@ -3,17 +3,16 @@
let let
inherit (lib) inherit (lib)
attrNames attrNames
concatMapAttrs concatMap
concatMapStrings concatMapStrings
flip
forEach forEach
head head
listToAttrs listToAttrs
mkDefault mkDefault
mkOption mkOption
nameValuePair nameValuePair
optionalAttrs
optionalString optionalString
optionals
range range
toLower toLower
types types
@ -92,24 +91,23 @@ 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.hosts = concatMapAttrs ( networking.extraHosts = flip concatMapStrings (attrNames nodes) (
name: config: m':
let let
config = nodes.${m'};
hostnames = hostnames =
[ optionalString (
"${config.networking.hostName}" config.networking.domain != null
] ) "${config.networking.hostName}.${config.networking.domain} "
++ optionals (config.networking.domain != null) [ + "${config.networking.hostName}\n";
"${config.networking.hostName}.${config.networking.domain}"
];
in in
optionalAttrs (config.networking.primaryIPAddress != "") { optionalString (
"${config.networking.primaryIPAddress}" = hostnames; config.networking.primaryIPAddress != ""
} ) "${config.networking.primaryIPAddress} ${hostnames}"
// optionalAttrs (config.networking.primaryIPv6Address != "") { + optionalString (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,12 +365,9 @@ in
keyFile = mkDefault key; keyFile = mkDefault key;
trustedCaFile = mkDefault caCert; trustedCaFile = mkDefault caCert;
}; };
networking.hosts = mkIf (config.services.etcd.enable) { networking.extraHosts = mkIf (config.services.etcd.enable) ''
"127.0.0.1" = [ 127.0.0.1 etcd.${top.addons.dns.clusterDomain} etcd.local
"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,12 +70,10 @@ in
# Rely on GCP's firewall instead # Rely on GCP's firewall instead
networking.firewall.enable = mkDefault false; networking.firewall.enable = mkDefault false;
networking.hosts = { # Configure default metadata hostnames
"169.254.169.254" = [ networking.extraHosts = ''
"metadata.google.internal" 169.254.169.254 metadata.google.internal metadata
"metadata" '';
];
};
networking.timeServers = [ "metadata.google.internal" ]; networking.timeServers = [ "metadata.google.internal" ];

View file

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