populate ip address based on hostname and populate the hostfile with other vm ips
This commit is contained in:
parent
a6db8ef50f
commit
c78fca0751
7 changed files with 54 additions and 4 deletions
|
@ -14,6 +14,5 @@
|
|||
|
||||
# System configuration here
|
||||
networking.hostName = "ghatanothoa";
|
||||
vmNetwork.ipv4 = "192.168.0.25";
|
||||
system.stateVersion = "23.11";
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
};
|
||||
|
||||
networking.hostName = "lobon";
|
||||
vmNetwork.ipv4 = "192.168.0.22";
|
||||
system.stateVersion = "23.11";
|
||||
|
||||
sops.secrets = {
|
||||
|
|
|
@ -11,6 +11,5 @@
|
|||
environment.systemPackages = [pkgs.git];
|
||||
|
||||
networking.hostName = "nodens";
|
||||
vmNetwork.ipv4 = "192.168.0.18";
|
||||
system.stateVersion = "24.11";
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
};
|
||||
|
||||
networking.hostName = "nyarlathotep";
|
||||
vmNetwork.ipv4 = "192.168.0.17";
|
||||
system.stateVersion = "24.05";
|
||||
|
||||
sops.secrets = let
|
||||
|
|
23
nixos/roles/hostmap.nix
Normal file
23
nixos/roles/hostmap.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"192.168.1.11" = ["bragi"];
|
||||
"192.168.0.13" = ["tsathoggua"];
|
||||
"192.168.0.14" = ["nyogtha"];
|
||||
"192.168.0.15" = ["hastur"];
|
||||
"192.168.0.16" = ["cthulhu"];
|
||||
"192.168.0.17" = ["nyarlathotep"];
|
||||
"192.168.0.18" = ["nodens"];
|
||||
"192.168.0.19" = ["uvhash"];
|
||||
"192.168.0.20" = ["aphoom-zhah"];
|
||||
"192.168.0.21" = ["dagon"];
|
||||
"192.168.0.22" = ["lobon"];
|
||||
"192.168.0.23" = ["yibb-tstll"];
|
||||
"192.168.0.24" = ["eihort"];
|
||||
"192.168.0.25" = ["ghatanothoa"];
|
||||
"192.168.0.26" = ["toth"];
|
||||
"192.168.0.27" = ["ithaqua"];
|
||||
"192.168.0.28" = ["nyarlathotep"];
|
||||
"192.168.0.29" = ["nixos-installer"];
|
||||
"192.168.0.30" = ["cthugha"];
|
||||
"192.168.0.40" = ["nerf-nixos-testlab"];
|
||||
"192.168.0.92" = ["sanctamariamaterdei"];
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
{modulesPath, ...}: {
|
||||
imports = [
|
||||
(modulesPath + "/virtualisation/xen-domU.nix")
|
||||
./vmNetwork.nix
|
||||
];
|
||||
}
|
||||
|
|
30
nixos/roles/vmNetwork.nix
Normal file
30
nixos/roles/vmNetwork.nix
Normal file
|
@ -0,0 +1,30 @@
|
|||
# This module assumes that every hostName of a machine in this repo only appears in one of the ip addresses,
|
||||
# to derive the ip adress based on the hostname this will need patching if we will ever have a vm with multiple
|
||||
# outward facing network interfaces.
|
||||
# (other hostnames can appear multiple times)
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) lists;
|
||||
inherit (builtins) elem;
|
||||
# taken from aza /etc/hosts
|
||||
hostmap = import ./hostmap.nix;
|
||||
myhostName = config.networking.hostName;
|
||||
# We replace our own ip with 127.0.0.1 in /etc/hosts
|
||||
myhosts = lib.attrsets.concatMapAttrs (ip: hosts:
|
||||
if (elem myhostName hosts)
|
||||
# nixos maps the hostname to the loopback 127.0.0.2 by default, so we exclude it here.
|
||||
# there is also a default localhost to 127.0.0.1 in place
|
||||
then {"127.0.0.1" = lists.filter (x: x != myhostName) hosts;}
|
||||
else {${ip} = hosts;})
|
||||
hostmap;
|
||||
myIp = (lists.findSingle (x: elem myhostName x.value) (throw "The machine has no ip address in nixos/roles/hostmap.nix") (throw "The ip for this machine is not unique in nixos/roles/hostmap.nix") (lib.attrsToList hostmap)).name;
|
||||
in {
|
||||
imports = [
|
||||
../modules/vmNetwork.nix
|
||||
];
|
||||
networking.hosts = myhosts;
|
||||
vmNetwork.ipv4 = myIp;
|
||||
}
|
Loading…
Add table
Reference in a new issue