nix-config/hosts/elisabeth/guests.nix

143 lines
4.5 KiB
Nix
Raw Normal View History

{
config,
2024-12-22 00:10:37 +01:00
globals,
stateVersion,
inputs,
lib,
minimal,
...
2024-07-26 22:12:48 +02:00
}:
{
2024-03-14 20:07:10 +01:00
2024-07-26 22:12:48 +02:00
guests =
let
mkGuest =
guestName:
{
enablePanzer ? false,
enableRenaultFT ? false,
enableBunker ? false,
enableSharedPaperless ? false,
2024-12-22 00:10:37 +01:00
vlans ? [ "services" ],
2024-07-26 22:12:48 +02:00
...
}:
{
2024-07-26 22:12:48 +02:00
autostart = true;
zfs."/state" = {
pool = "rpool";
dataset = "local/guests/${guestName}";
};
2024-07-26 22:12:48 +02:00
zfs."/persist" = {
pool = "rpool";
dataset = "safe/guests/${guestName}";
};
zfs."/panzer" = lib.mkIf enablePanzer {
pool = "panzer";
dataset = "safe/guests/${guestName}";
};
zfs."/renaultft" = lib.mkIf enableRenaultFT {
pool = "renaultft";
dataset = "safe/guests/${guestName}";
};
# kinda not necesarry should be removed on next reimaging
zfs."/bunker" = lib.mkIf enableBunker {
pool = "panzer";
dataset = "bunker/guests/${guestName}";
};
zfs."/paperless" = lib.mkIf enableSharedPaperless {
pool = "panzer";
dataset = "bunker/shared/paperless";
};
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-22 00:10:37 +01:00
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)
(lib.net.cidr.hostCidr globals.services.${guestName}.ip globals.net.vlans.${name}.cidrv6)
];
gateway = [
(lib.net.cidr.hostCidr 1 globals.net.vlans.${name}.cidrv4)
(lib.net.cidr.hostCidr 1 globals.net.vlans.${name}.cidrv6)
];
}
)
)
);
2024-07-26 22:12:48 +02:00
}
];
};
2024-07-26 22:12:48 +02: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-01-21 00:43:50 +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;
inherit (inputs.self.pkgs.x86_64-linux) lib;
inherit inputs minimal stateVersion;
};
};
2024-07-26 22:12:48 +02:00
};
2024-12-22 00:10:37 +01:00
mkContainer =
guestName:
{
vlans ? [ "services" ],
...
}@cfg:
{
${guestName} = 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-07-26 22:12:48 +02:00
in
{ }
// mkContainer "adguardhome" { }
// mkContainer "oauth2-proxy" { }
// mkContainer "vaultwarden" { }
// mkContainer "ddclient" { }
// mkContainer "ollama" { }
// mkContainer "murmur" { }
2024-09-01 19:51:52 +02:00
// mkContainer "homebox" { }
2024-08-23 00:30:11 +02:00
// mkContainer "invidious" { }
2024-07-26 22:12:48 +02:00
// mkContainer "ttrss" { }
// mkContainer "firefly" { }
// mkContainer "yourspotify" { }
// mkContainer "netbird" { }
2024-09-01 15:53:19 +02:00
// mkContainer "blog" { }
2024-07-26 22:12:48 +02:00
// mkContainer "kanidm" { }
// mkContainer "nextcloud" { enablePanzer = true; }
// mkContainer "paperless" { enableSharedPaperless = true; }
// mkContainer "forgejo" { enablePanzer = true; }
// mkMicrovm "immich" { enablePanzer = true; }
// mkContainer "samba" {
enablePanzer = true;
enableRenaultFT = true;
2024-01-18 00:39:25 +01:00
enableBunker = true;
enableSharedPaperless = true;
2024-12-22 00:10:37 +01:00
vlans = [ "home" ];
};
}