chore: support static ips

This commit is contained in:
Patrick 2024-12-21 14:06:00 +01:00
parent 053365c277
commit 5d1bc8cf67
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
4 changed files with 82 additions and 34 deletions

View file

@ -9,6 +9,8 @@ let
ipOf = name: nodes.${globals.services.${name}.host}.config.wireguard.services.ipv4;
in
{
systemd.network.networks."10-static" = {
};
wireguard.services = {
client.via = "nucnix";
};

View file

@ -49,6 +49,7 @@ in
adguardhome = {
domain = "adguardhome.${globals.domains.web}";
host = "nucnix-adguardhome";
ip = 10;
};
forgejo = {
domain = "forge.${globals.domains.web}";
@ -84,7 +85,7 @@ in
};
apispotify = {
domain = "apisptfy.${globals.domains.web}";
host = "elisabeth-apispotify";
host = "elisabeth-yourspotify";
};
kanidm = {
domain = "auth.${globals.domains.web}";
@ -118,6 +119,16 @@ in
domain = "netbird.${globals.domains.web}";
host = "elisabeth-netbird";
};
nginx = {
domain = globals.domains.web;
host = "nucnix-nginx";
ip = 5;
};
samba = {
domain = "smb.${globals.domains.web}";
host = "elisabeth-samba";
ip = 12;
};
};
};
}

View file

@ -1,6 +1,7 @@
{
config,
stateVersion,
globals,
inputs,
lib,
minimal,
@ -9,7 +10,13 @@
{
guests =
let
mkGuest = guestName: _: {
mkGuest =
guestName:
{
vlans ? [ "services" ],
...
}:
{
autostart = true;
zfs."/state" = {
pool = "rpool";
@ -27,6 +34,21 @@
networking.nftables.firewall.zones.untrusted.interfaces = lib.mkIf (
lib.length config.guests.${guestName}.networking.links == 1
) config.guests.${guestName}.networking.links;
systemd.network.networks = lib.mkIf (globals.services.${guestName}.ip != null) (
lib.listToAttrs (
lib.flip map vlans (
name:
lib.nameValuePair "09-mv-${name}" {
matchConfig.Name = "mv-${name}";
DHCP = "no";
address = [
(lib.net.cidr.hostCidr globals.services.${guestName}.ip globals.net.vlans.${name}.cidrv4)
];
gateway = lib.net.cidr.hostCidr 1 globals.net.vlans.${name}.cidrv4;
}
)
)
);
}
];
};
@ -36,7 +58,7 @@
backend = "microvm";
microvm = {
system = "x86_64-linux";
interfaces.lan = { };
interfaces.lan = lib.trace "This don't work yet" { };
baseMac = config.secrets.secrets.local.networking.interfaces.lan01.mac;
};
extraSpecialArgs = {
@ -50,22 +72,30 @@
mkContainer =
guestName:
{
macvlans ? [ "lan-services" ],
vlans ? [ "services" ],
...
}@cfg:
{
${guestName} = mkGuest guestName cfg // {
${guestName} = lib.mkMerge [
(mkGuest guestName cfg)
{
backend = "container";
container.macvlans = macvlans;
container.macvlans = lib.flip map vlans (x: "lan-${x}:mv-${x}");
extraSpecialArgs = {
inherit (inputs.self) nodes globals;
inherit (inputs.self.pkgs.x86_64-linux) lib;
inherit inputs minimal stateVersion;
};
};
}
];
};
in
{ }
// mkContainer "adguardhome" { macvlans = [ "lan-services" ]; }
// mkContainer "nginx" { macvlans = [ "lan-services" ]; };
// mkContainer "adguardhome" {
vlans = [
"services"
"home"
];
}
// mkContainer "nginx" { };
}

View file

@ -132,6 +132,11 @@ in
type = types.str;
description = "The node-name on which this service runs";
};
ip = mkOption {
type = types.nullOr (types.ints.between 5 49);
default = null;
description = "Optional IP in case this service runs needs a static ip. Shou";
};
};
}
);