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

View file

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

View file

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

View file

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