2024-12-14 21:45:46 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
stateVersion,
|
2024-12-21 14:06:00 +01:00
|
|
|
globals,
|
2024-12-14 21:45:46 +01:00
|
|
|
inputs,
|
|
|
|
lib,
|
|
|
|
minimal,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
guests =
|
|
|
|
let
|
2024-12-21 14:06:00 +01:00
|
|
|
mkGuest =
|
|
|
|
guestName:
|
|
|
|
{
|
|
|
|
vlans ? [ "services" ],
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
autostart = true;
|
|
|
|
zfs."/state" = {
|
|
|
|
pool = "rpool";
|
|
|
|
dataset = "local/guests/${guestName}";
|
|
|
|
};
|
|
|
|
zfs."/persist" = {
|
|
|
|
pool = "rpool";
|
|
|
|
dataset = "safe/guests/${guestName}";
|
|
|
|
};
|
|
|
|
modules = [
|
|
|
|
../../config/basic
|
|
|
|
../../config/services/${guestName}.nix
|
|
|
|
{
|
|
|
|
node.secretsDir = config.node.secretsDir + "/${guestName}";
|
|
|
|
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)
|
2024-12-21 23:32:42 +01:00
|
|
|
(lib.net.cidr.hostCidr globals.services.${guestName}.ip globals.net.vlans.${name}.cidrv6)
|
|
|
|
];
|
|
|
|
gateway = [
|
2024-12-22 19:00:21 +01:00
|
|
|
(lib.net.cidr.host 1 globals.net.vlans.${name}.cidrv4)
|
|
|
|
(lib.net.cidr.host 1 globals.net.vlans.${name}.cidrv6)
|
2024-12-21 14:06:00 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
];
|
2024-12-14 21:45:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mkMicrovm = guestName: cfg: {
|
|
|
|
${guestName} = mkGuest guestName cfg // {
|
|
|
|
backend = "microvm";
|
|
|
|
microvm = {
|
|
|
|
system = "x86_64-linux";
|
2024-12-21 14:06:00 +01:00
|
|
|
interfaces.lan = lib.trace "This don't work yet" { };
|
2024-12-14 21:45:46 +01:00
|
|
|
baseMac = config.secrets.secrets.local.networking.interfaces.lan01.mac;
|
|
|
|
};
|
|
|
|
extraSpecialArgs = {
|
2024-12-20 20:40:27 +01:00
|
|
|
inherit (inputs.self) nodes globals;
|
2024-12-14 21:45:46 +01:00
|
|
|
inherit (inputs.self.pkgs.x86_64-linux) lib;
|
|
|
|
inherit inputs minimal stateVersion;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-20 11:07:22 +01:00
|
|
|
mkContainer =
|
|
|
|
guestName:
|
|
|
|
{
|
2024-12-21 14:06:00 +01:00
|
|
|
vlans ? [ "services" ],
|
2024-12-20 11:07:22 +01:00
|
|
|
...
|
|
|
|
}@cfg:
|
|
|
|
{
|
2024-12-21 14:06:00 +01:00
|
|
|
${guestName} = lib.mkMerge [
|
|
|
|
(mkGuest guestName cfg)
|
|
|
|
{
|
|
|
|
backend = "container";
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2024-12-14 21:45:46 +01:00
|
|
|
};
|
|
|
|
in
|
2024-12-21 23:32:42 +01:00
|
|
|
{ } // mkContainer "adguardhome" { } // mkContainer "nginx" { };
|
2024-12-14 21:45:46 +01:00
|
|
|
}
|