Skip to content

Commit cd64f1b

Browse files
committed
treewide: migrate nixos modules to networking.hosts
Signed-off-by: John Titor <[email protected]>
1 parent d859e3f commit cd64f1b

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

nixos/lib/testing/network.nix

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
let
44
inherit (lib)
55
attrNames
6-
concatMap
6+
concatMapAttrs
77
concatMapStrings
8-
flip
98
forEach
109
head
1110
listToAttrs
1211
mkDefault
1312
mkOption
1413
nameValuePair
14+
optionalAttrs
1515
optionalString
1616
range
1717
toLower
@@ -91,23 +91,22 @@ let
9191
# interfaces, use the IP address corresponding to
9292
# the first interface (i.e. the first network in its
9393
# virtualisation.vlans option).
94-
networking.extraHosts = flip concatMapStrings (attrNames nodes) (
95-
m':
94+
networking.hosts = concatMapAttrs (
95+
name: config:
9696
let
97-
config = nodes.${m'};
9897
hostnames =
9998
optionalString (
10099
config.networking.domain != null
101100
) "${config.networking.hostName}.${config.networking.domain} "
102101
+ "${config.networking.hostName}\n";
103102
in
104-
optionalString (
105-
config.networking.primaryIPAddress != ""
106-
) "${config.networking.primaryIPAddress} ${hostnames}"
107-
+ optionalString (config.networking.primaryIPv6Address != "") (
108-
"${config.networking.primaryIPv6Address} ${hostnames}"
109-
)
110-
);
103+
optionalAttrs (config.networking.primaryIPAddress != "") {
104+
"${config.networking.primaryIPAddress}" = [ hostnames ];
105+
}
106+
// optionalAttrs (config.networking.primaryIPv6Address != "") {
107+
"${config.networking.primaryIPv6Address}" = [ hostnames ];
108+
}
109+
) nodes;
111110

112111
virtualisation.qemu.options = qemuOptions;
113112
boot.initrd.services.udev.rules = concatMapStrings (x: x + "\n") udevRules;

nixos/modules/services/cluster/kubernetes/pki.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,12 @@ in
365365
keyFile = mkDefault key;
366366
trustedCaFile = mkDefault caCert;
367367
};
368-
networking.extraHosts = mkIf (config.services.etcd.enable) ''
369-
127.0.0.1 etcd.${top.addons.dns.clusterDomain} etcd.local
370-
'';
368+
networking.hosts = mkIf (config.services.etcd.enable) {
369+
"127.0.0.1" = [
370+
"etcd.${top.addons.dns.clusterDomain}"
371+
"etcd.local"
372+
];
373+
};
371374

372375
services.flannel = with cfg.certs.flannelClient; {
373376
kubeconfig = top.lib.mkKubeConfig "flannel" {

nixos/modules/virtualisation/google-compute-config.nix

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ in
7070
# Rely on GCP's firewall instead
7171
networking.firewall.enable = mkDefault false;
7272

73-
# Configure default metadata hostnames
74-
networking.extraHosts = ''
75-
169.254.169.254 metadata.google.internal metadata
76-
'';
73+
networking.hosts = {
74+
"169.254.169.254" = [
75+
"metadata.google.internal"
76+
"metadata"
77+
];
78+
};
7779

7880
networking.timeServers = [ "metadata.google.internal" ];
7981

nixos/modules/virtualisation/nixos-containers.nix

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,14 +1084,10 @@ in
10841084
) config.containers;
10851085

10861086
# Generate /etc/hosts entries for the containers.
1087-
networking.extraHosts = concatStrings (
1088-
mapAttrsToList (
1089-
name: cfg:
1090-
optionalString (cfg.localAddress != null) ''
1091-
${head (splitString "/" cfg.localAddress)} ${name}.containers
1092-
''
1093-
) config.containers
1094-
);
1087+
networking.hosts = lib.mapAttrs' (name: cfg: {
1088+
name = head (splitString "/" cfg.localAddress);
1089+
value = lib.optionals (cfg.localAddress != null) [ "${name}.containers" ];
1090+
}) config.containers;
10951091

10961092
networking.dhcpcd.denyInterfaces = [
10971093
"ve-*"

0 commit comments

Comments
 (0)