nix-config/hosts/nucnix/guests.nix

72 lines
1.9 KiB
Nix
Raw Normal View History

2024-12-14 21:45:46 +01:00
{
config,
stateVersion,
inputs,
lib,
minimal,
...
}:
{
guests =
let
mkGuest = guestName: _: {
2024-12-14 21:45:46 +01:00
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}";
2024-12-20 20:40:27 +01:00
networking.nftables.firewall.zones.untrusted.interfaces = lib.mkIf (
lib.length config.guests.${guestName}.networking.links == 1
) config.guests.${guestName}.networking.links;
2024-12-14 21:45:46 +01:00
}
];
};
mkMicrovm = guestName: cfg: {
${guestName} = mkGuest guestName cfg // {
backend = "microvm";
microvm = {
system = "x86_64-linux";
2024-12-20 20:40:27 +01:00
interfaces.lan = { };
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;
};
};
};
mkContainer =
guestName:
{
macvlans ? [ "lan-services" ],
...
}@cfg:
{
${guestName} = mkGuest guestName cfg // {
backend = "container";
container.macvlans = macvlans;
extraSpecialArgs = {
2024-12-20 20:40:27 +01:00
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-20 20:40:27 +01:00
{ }
// mkContainer "adguardhome" { macvlans = [ "lan-services" ]; }
// mkContainer "nginx" { macvlans = [ "lan-services" ]; };
2024-12-14 21:45:46 +01:00
}