From c87464cb0c35a306ec4bbaacc17b704e40cef0cc Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Mon, 9 Jun 2025 00:10:05 +0530 Subject: [PATCH] Revert "treewide: migrate nixos modules to networking.hosts" This reverts commit cd64f1bd874fbae5beaf0fcb39e05c2da75b16e1. --- nixos/lib/testing/network.nix | 23 ++++++++++--------- .../services/cluster/kubernetes/pki.nix | 9 +++----- .../virtualisation/google-compute-config.nix | 10 ++++---- .../virtualisation/nixos-containers.nix | 12 ++++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/nixos/lib/testing/network.nix b/nixos/lib/testing/network.nix index 2a188e480ecb..5caea2710754 100644 --- a/nixos/lib/testing/network.nix +++ b/nixos/lib/testing/network.nix @@ -3,15 +3,15 @@ let inherit (lib) attrNames - concatMapAttrs + concatMap concatMapStrings + flip forEach head listToAttrs mkDefault mkOption nameValuePair - optionalAttrs optionalString range toLower @@ -91,22 +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 = 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; diff --git a/nixos/modules/services/cluster/kubernetes/pki.nix b/nixos/modules/services/cluster/kubernetes/pki.nix index 0453091fb9b6..e4f8cf44e703 100644 --- a/nixos/modules/services/cluster/kubernetes/pki.nix +++ b/nixos/modules/services/cluster/kubernetes/pki.nix @@ -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" { diff --git a/nixos/modules/virtualisation/google-compute-config.nix b/nixos/modules/virtualisation/google-compute-config.nix index 3b6387a3a565..8f9e2b4f4075 100644 --- a/nixos/modules/virtualisation/google-compute-config.nix +++ b/nixos/modules/virtualisation/google-compute-config.nix @@ -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" ]; diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index 1854a279285d..e5a0d37d6a9c 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -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-*"