Skip to content

Commit d25d522

Browse files
committed
examples/microvms-host: populate /etc/hosts
1 parent a8678ad commit d25d522

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

examples/microvms-host.nix

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ nixpkgs.lib.nixosSystem {
1212

1313
({ config, lib, pkgs, ... }:
1414
let
15+
inherit (self.lib) hypervisors;
16+
1517
hypervisorMacAddrs = builtins.listToAttrs (
1618
map (hypervisor:
1719
let
@@ -21,7 +23,16 @@ nixpkgs.lib.nixosSystem {
2123
in {
2224
name = hypervisor;
2325
value = mac;
24-
}) self.lib.hypervisors);
26+
}) hypervisors
27+
);
28+
29+
hypervisorIPv4Addrs = builtins.listToAttrs (
30+
lib.imap0 (i: hypervisor: {
31+
name = hypervisor;
32+
value = "10.0.0.${toString (2 + i)}";
33+
}) hypervisors
34+
);
35+
2536
in {
2637
networking.hostName = "microvms-host";
2738
system.stateVersion = config.system.nixos.version;
@@ -98,9 +109,9 @@ nixpkgs.lib.nixosSystem {
98109
dhcpServerStaticLeases = lib.imap0 (i: hypervisor: {
99110
dhcpServerStaticLeaseConfig = {
100111
MACAddress = hypervisorMacAddrs.${hypervisor};
101-
Address = "10.0.0.${toString (2 + i)}";
112+
Address = hypervisorIPv4Addrs.${hypervisor};
102113
};
103-
}) (builtins.attrNames hypervisorMacAddrs);
114+
}) hypervisors;
104115
# IPv6 SLAAC
105116
ipv6Prefixes = [ {
106117
ipv6PrefixConfig.Prefix = "fd12:3456:789a::/64";
@@ -119,6 +130,10 @@ nixpkgs.lib.nixosSystem {
119130
enableIPv6 = true;
120131
internalInterfaces = [ "virbr0" ];
121132
};
133+
134+
networking.extraHosts = lib.concatMapStrings (hypervisor: ''
135+
${hypervisorIPv4Addrs.${hypervisor}} ${hypervisor}
136+
'') hypervisors;
122137
})
123138
];
124139
}

0 commit comments

Comments
 (0)