nixfiles/nixos/boxes/colony/vms/estuary/default.nix

211 lines
6.9 KiB
Nix
Raw Normal View History

{ lib, ... }: {
nixos.systems.estuary = {
system = "x86_64-linux";
nixpkgs = "mine";
home-manager = "mine";
assignments = {
internal = {
name = "estuary-vm";
altNames = [ "fw" ];
2022-06-05 16:40:44 +01:00
domain = lib.my.colony.domain;
ipv4 = {
2022-06-05 16:41:57 +01:00
address = "188.141.14.75";
gateway = null;
2022-06-05 16:21:24 +01:00
genPTR = false;
};
ipv6 = {
address = "2a0e:97c0:4d0:bbbf::1";
gateway = "fe80::215:17ff:fe4b:494a";
};
};
base = {
ipv4 = {
address = "${lib.my.colony.start.base.v4}1";
gateway = null;
};
ipv6.address = "${lib.my.colony.start.base.v6}1";
2022-05-17 23:27:14 +01:00
};
};
configuration = { lib, pkgs, modulesPath, config, assignments, allAssignments, ... }:
let
2022-05-18 22:52:42 +01:00
inherit (lib) mkIf mkMerge mkForce;
2022-05-17 23:27:14 +01:00
inherit (lib.my) networkdAssignment;
in
{
imports = [ "${modulesPath}/profiles/qemu-guest.nix" ./dns.nix ];
config = mkMerge [
{
boot.kernelParams = [ "console=ttyS0,115200n8" ];
fileSystems = {
"/boot" = {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
};
"/nix" = {
device = "/dev/main/nix";
fsType = "ext4";
};
"/persist" = {
device = "/dev/main/persist";
fsType = "ext4";
neededForBoot = true;
};
};
services = {
lvm = {
dmeventd.enable = true;
};
};
systemd.network = {
links = {
"10-wan" = {
matchConfig.MACAddress = "52:54:00:a1:b2:5f";
linkConfig.Name = "wan";
};
"10-base" = {
matchConfig.MACAddress = "52:54:00:ab:f1:52";
linkConfig.Name = "base";
};
};
networks = {
"80-wan" = {
matchConfig.Name = "wan";
DHCP = "ipv4";
2022-05-23 00:57:25 +01:00
dhcpV4Config = {
UseDNS = false;
UseHostname = false;
};
address = [
(with assignments.internal.ipv6; "${address}/${toString mask}")
];
gateway = [
assignments.internal.ipv6.gateway
];
networkConfig.IPv6AcceptRA = false;
};
2022-05-18 22:52:42 +01:00
"80-base" = mkMerge [
(networkdAssignment "base" assignments.base)
2022-05-18 22:52:42 +01:00
{
2022-05-23 00:57:25 +01:00
dns = [ "127.0.0.1" "::1" ];
domains = [ config.networking.domain ];
2022-05-18 22:52:42 +01:00
networkConfig = {
IPv6AcceptRA = mkForce false;
IPv6SendRA = true;
};
2022-05-23 00:57:25 +01:00
ipv6SendRAConfig = {
DNS = [ assignments.base.ipv6.address ];
2022-05-23 00:57:25 +01:00
Domains = [ config.networking.domain ];
};
2022-05-18 22:52:42 +01:00
ipv6Prefixes = [
{
ipv6PrefixConfig.Prefix = lib.my.colony.prefixes.base.v6;
}
];
routes = map (r: { routeConfig = r; }) [
{
Gateway = allAssignments.colony.internal.ipv4.address;
Destination = lib.my.colony.prefixes.vms.v4;
}
{
Gateway = allAssignments.colony.internal.ipv6.address;
Destination = lib.my.colony.prefixes.vms.v6;
}
{
Gateway = allAssignments.colony.internal.ipv4.address;
Destination = lib.my.colony.prefixes.ctrs.v4;
}
{
Gateway = allAssignments.colony.internal.ipv6.address;
Destination = lib.my.colony.prefixes.ctrs.v6;
2022-05-18 22:52:42 +01:00
}
];
}
];
};
};
my = {
#deploy.generate.system.mode = "boot";
2022-05-28 19:02:13 +01:00
secrets.key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPhxM5mnguExkcLue47QKk1vA72OoPc3HOqqoHqHHfa1";
server.enable = true;
firewall = {
trustedInterfaces = [ "base" ];
udp.allowed = [ 5353 ];
tcp.allowed = [ 5353 ];
nat = {
enable = true;
externalInterface = "wan";
2022-06-06 00:57:11 +01:00
forwardPorts = [
{
port = "http";
dst = allAssignments.middleman.internal.ipv4.address + ":http";
}
{
port = "https";
dst = allAssignments.middleman.internal.ipv4.address + ":https";
}
];
};
2022-05-31 21:25:51 +01:00
extraRules =
let
aa = allAssignments;
matchInet = rule: sys: ''
ip daddr ${aa."${sys}".internal.ipv4.address} ${rule}
ip6 daddr ${aa."${sys}".internal.ipv6.address} ${rule}
'';
in
''
table inet filter {
chain routing-tcp {
# Safe enough to allow all SSH
tcp dport ssh accept
2022-05-31 21:25:51 +01:00
${matchInet "tcp dport { http, https } accept" "middleman"}
return
}
chain routing-udp {
2022-05-31 21:25:51 +01:00
return
}
chain filter-routing {
tcp flags & (fin|syn|rst|ack) == syn ct state new jump routing-tcp
meta l4proto udp ct state new jump routing-udp
return
}
chain forward {
iifname wan oifname base jump filter-routing
}
}
table inet nat {
chain prerouting {
2022-06-06 00:18:24 +01:00
${matchInet "meta l4proto { udp, tcp } th dport domain redirect to :5353" "estuary"}
}
chain postrouting {
ip saddr ${lib.my.colony.prefixes.all.v4} masquerade
}
}
'';
};
};
}
(mkIf config.my.build.isDevVM {
systemd.network = {
netdevs."05-dummy-base".netdevConfig = {
Name = "base";
Kind = "dummy";
};
};
})
];
};
};
}