Skip to content

Commit

Permalink
examples/microvms-host: populate /etc/hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Mar 21, 2024
1 parent a8678ad commit d25d522
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions examples/microvms-host.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ nixpkgs.lib.nixosSystem {

({ config, lib, pkgs, ... }:
let
inherit (self.lib) hypervisors;

hypervisorMacAddrs = builtins.listToAttrs (
map (hypervisor:
let
Expand All @@ -21,7 +23,16 @@ nixpkgs.lib.nixosSystem {
in {
name = hypervisor;
value = mac;
}) self.lib.hypervisors);
}) hypervisors
);

hypervisorIPv4Addrs = builtins.listToAttrs (
lib.imap0 (i: hypervisor: {
name = hypervisor;
value = "10.0.0.${toString (2 + i)}";
}) hypervisors
);

in {
networking.hostName = "microvms-host";
system.stateVersion = config.system.nixos.version;
Expand Down Expand Up @@ -98,9 +109,9 @@ nixpkgs.lib.nixosSystem {
dhcpServerStaticLeases = lib.imap0 (i: hypervisor: {
dhcpServerStaticLeaseConfig = {
MACAddress = hypervisorMacAddrs.${hypervisor};
Address = "10.0.0.${toString (2 + i)}";
Address = hypervisorIPv4Addrs.${hypervisor};
};
}) (builtins.attrNames hypervisorMacAddrs);
}) hypervisors;
# IPv6 SLAAC
ipv6Prefixes = [ {
ipv6PrefixConfig.Prefix = "fd12:3456:789a::/64";
Expand All @@ -119,6 +130,10 @@ nixpkgs.lib.nixosSystem {
enableIPv6 = true;
internalInterfaces = [ "virbr0" ];
};

networking.extraHosts = lib.concatMapStrings (hypervisor: ''
${hypervisorIPv4Addrs.${hypervisor}} ${hypervisor}
'') hypervisors;
})
];
}

0 comments on commit d25d522

Please sign in to comment.