Compare commits

..

1 commit

2 changed files with 63 additions and 28 deletions

View file

@ -1,21 +1,54 @@
# This data is taken from /etc/hosts from azatoth
{
"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.30" = ["cthugha"];
"192.168.0.92" = ["sanctamariamaterdei"];
bragi = {
ipv4 = "192.168.1.11";
};
tsathoggua = {
ipv4 = "192.168.0.13";
};
nyogtha = {
ipv4 = "192.168.0.14";
};
hastur = {
ipv4 = "192.168.0.15";
};
cthulhu = {
ipv4 = "192.168.0.16";
};
nyarlathotep = {
ipv4 = "192.168.0.17";
};
nodens = {
ipv4 = "192.168.0.18";
};
uvhash = {
ipv4 = "192.168.0.19";
};
aphoom-zhah = {
ipv4 = "192.168.0.20";
};
dagon = {
ipv4 = "192.168.0.21";
};
lobon = {
ipv4 = "192.168.0.22";
};
yibb-tstll = {
ipv4 = "192.168.0.23";
};
eihort = {
ipv4 = "192.168.0.24";
};
ghatanothoa = {
ipv4 = "192.168.0.25";
};
toth = {
ipv4 = "192.168.0.26";
};
ithaqua = {
ipv4 = "192.168.0.27";
};
cthugha = {
ipv4 = "192.168.0.30";
};
}

View file

@ -1,26 +1,28 @@
# 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 (lib) lists mapAttrsToList;
inherit (lib.attrsets) foldAttrs concatMapAttrs;
inherit (lib.asserts) assertMsg;
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:
# To turn the hostmap around suitable for networking.hosts the following simple code almost works
# concatMapAttrs (hostname: ipData: { ${ipData.ipv4} = [hostname]; }) hostmap
# but breaks as soon as we want to map two different names to the same ip.
# So the code looks uglier than one would expect.
globalhosts = foldAttrs (a: b: a ++ b) [] (mapAttrsToList (hostname: ipData: {${ipData.ipv4} = [hostname];}) hostmap);
myhosts = 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;
globalhosts;
myIp = assert assertMsg hostmap ? ${myhostName}.ipv4 "${myhostName} has no ip configured in nixos/roles/hostmap.nix"; hostmap.${myhostName}.ipv4;
in {
imports = [
../modules/vmNetwork.nix