2022-05-31 21:58:29 +01:00
|
|
|
{ lib, ... }: {
|
2022-05-16 00:05:02 +01:00
|
|
|
nixos.systems.estuary = {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
nixpkgs = "mine";
|
2022-05-28 18:38:03 +01:00
|
|
|
home-manager = "mine";
|
2022-05-16 00:05:02 +01:00
|
|
|
|
2022-05-29 15:48:26 +01:00
|
|
|
assignments = {
|
|
|
|
internal = {
|
|
|
|
name = "estuary-vm";
|
|
|
|
altNames = [ "fw" ];
|
2022-06-05 16:40:44 +01:00
|
|
|
domain = lib.my.colony.domain;
|
2022-05-29 15:48:26 +01:00
|
|
|
ipv4 = {
|
2022-07-01 01:02:55 +01:00
|
|
|
address = "212.83.51.97";
|
|
|
|
mask = 24;
|
|
|
|
gateway = "212.83.51.1";
|
2022-06-05 16:21:24 +01:00
|
|
|
genPTR = false;
|
2022-05-29 15:48:26 +01:00
|
|
|
};
|
|
|
|
ipv6 = {
|
2022-07-01 01:02:55 +01:00
|
|
|
address = "2a00:f48:103:2::10";
|
|
|
|
mask = 64;
|
|
|
|
gateway = "2a00:f48:103:2::1";
|
|
|
|
genPTR = false;
|
2022-05-29 15:48:26 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
base = {
|
2022-06-10 20:42:13 +01:00
|
|
|
name = "estuary-vm-base";
|
|
|
|
domain = lib.my.colony.domain;
|
2022-05-29 15:48:26 +01:00
|
|
|
ipv4 = {
|
2022-05-31 21:58:29 +01:00
|
|
|
address = "${lib.my.colony.start.base.v4}1";
|
2022-05-29 15:48:26 +01:00
|
|
|
gateway = null;
|
|
|
|
};
|
2022-05-31 21:58:29 +01:00
|
|
|
ipv6.address = "${lib.my.colony.start.base.v6}1";
|
2022-05-17 23:27:14 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-22 23:24:57 +01:00
|
|
|
configuration = { lib, pkgs, modulesPath, config, assignments, allAssignments, ... }:
|
2022-05-16 00:05:02 +01:00
|
|
|
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;
|
2022-05-16 00:05:02 +01:00
|
|
|
in
|
|
|
|
{
|
2022-05-22 23:24:57 +01:00
|
|
|
imports = [ "${modulesPath}/profiles/qemu-guest.nix" ./dns.nix ];
|
2022-05-16 00:05:02 +01:00
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
{
|
|
|
|
boot.kernelParams = [ "console=ttyS0,115200n8" ];
|
|
|
|
fileSystems = {
|
|
|
|
"/boot" = {
|
|
|
|
device = "/dev/disk/by-label/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
"/nix" = {
|
2022-06-06 15:53:57 +01:00
|
|
|
device = "/dev/disk/by-label/nix";
|
2022-05-16 00:05:02 +01:00
|
|
|
fsType = "ext4";
|
|
|
|
};
|
|
|
|
"/persist" = {
|
2022-06-06 15:53:57 +01:00
|
|
|
device = "/dev/disk/by-label/persist";
|
2022-05-16 00:05:02 +01:00
|
|
|
fsType = "ext4";
|
|
|
|
neededForBoot = true;
|
|
|
|
};
|
|
|
|
};
|
2022-05-22 23:24:57 +01:00
|
|
|
|
2022-05-16 00:05:02 +01:00
|
|
|
services = {
|
|
|
|
lvm = {
|
|
|
|
dmeventd.enable = true;
|
|
|
|
};
|
2022-06-12 17:27:11 +01:00
|
|
|
netdata.enable = true;
|
2022-06-18 02:13:54 +01:00
|
|
|
|
|
|
|
iperf3 = {
|
|
|
|
enable = true;
|
|
|
|
openFirewall = true;
|
|
|
|
};
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
|
|
|
|
2022-07-07 23:49:22 +01:00
|
|
|
systemd = {
|
|
|
|
services = {
|
|
|
|
# Use this as a way to make sure the router always knows we're here (NDP seems kindy funky)
|
|
|
|
ipv6-neigh-keepalive =
|
|
|
|
let
|
|
|
|
waitOnline = "systemd-networkd-wait-online@wan.service";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
enable = true;
|
|
|
|
requires = [ waitOnline ];
|
|
|
|
after = [ waitOnline ];
|
2022-07-10 16:18:20 +01:00
|
|
|
script = ''
|
|
|
|
while true; do
|
|
|
|
${pkgs.ndisc6}/bin/ndisc6 ${assignments.internal.ipv6.gateway} wan
|
|
|
|
sleep 10
|
|
|
|
done
|
|
|
|
'';
|
2022-07-07 23:49:22 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-16 00:05:02 +01:00
|
|
|
systemd.network = {
|
|
|
|
links = {
|
2022-07-01 01:02:55 +01:00
|
|
|
"10-phy1g0" = {
|
2022-06-17 01:47:51 +01:00
|
|
|
matchConfig.MACAddress = "d0:50:99:fa:a7:99";
|
2022-07-01 01:02:55 +01:00
|
|
|
linkConfig.Name = "phy1g0";
|
|
|
|
};
|
|
|
|
"10-wan" = {
|
|
|
|
matchConfig.MACAddress = "00:02:c9:56:24:6e";
|
2022-05-16 00:05:02 +01:00
|
|
|
linkConfig.Name = "wan";
|
|
|
|
};
|
2022-07-01 01:02:55 +01:00
|
|
|
|
2022-05-16 00:05:02 +01:00
|
|
|
"10-base" = {
|
2022-06-17 01:47:51 +01:00
|
|
|
matchConfig.MACAddress = "52:54:00:15:1a:53";
|
2022-05-16 00:05:02 +01:00
|
|
|
linkConfig.Name = "base";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networks = {
|
|
|
|
"80-wan" = {
|
|
|
|
matchConfig.Name = "wan";
|
2022-07-01 01:02:55 +01:00
|
|
|
DHCP = "no";
|
|
|
|
address = with assignments.internal; [
|
|
|
|
(with ipv4; "${address}/${toString mask}")
|
|
|
|
(with ipv6; "${address}/${toString mask}")
|
2022-05-28 22:59:50 +01:00
|
|
|
];
|
2022-07-01 01:02:55 +01:00
|
|
|
gateway = with assignments.internal; [
|
|
|
|
ipv4.gateway
|
|
|
|
ipv6.gateway
|
2022-05-28 22:59:50 +01:00
|
|
|
];
|
2022-07-06 20:51:51 +01:00
|
|
|
networkConfig = {
|
|
|
|
# We're using an explicit gateway and Linux uses link local address for neighbour discovery, so we
|
|
|
|
# get lost to the router...
|
|
|
|
LinkLocalAddressing = "no";
|
|
|
|
IPv6AcceptRA = false;
|
|
|
|
};
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
2022-05-18 22:52:42 +01:00
|
|
|
"80-base" = mkMerge [
|
2022-05-29 15:48:26 +01:00
|
|
|
(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 = {
|
2022-05-29 15:48:26 +01:00
|
|
|
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 = [
|
|
|
|
{
|
2022-05-29 03:30:40 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
my = {
|
2022-05-28 22:59:50 +01:00
|
|
|
#deploy.generate.system.mode = "boot";
|
2022-06-17 01:47:51 +01:00
|
|
|
secrets.key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF9up7pXu6M/OWCKufTOfSiGcxMUk4VqUe7fLuatNFFA";
|
2022-05-16 00:05:02 +01:00
|
|
|
server.enable = true;
|
|
|
|
|
|
|
|
firewall = {
|
|
|
|
trustedInterfaces = [ "base" ];
|
2022-05-28 22:59:50 +01:00
|
|
|
udp.allowed = [ 5353 ];
|
|
|
|
tcp.allowed = [ 5353 ];
|
2022-05-16 00:05:02 +01:00
|
|
|
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-06-11 01:20:32 +01:00
|
|
|
{
|
|
|
|
port = 8448;
|
|
|
|
dst = allAssignments.middleman.internal.ipv4.address + ":8448";
|
|
|
|
}
|
2022-06-06 00:57:11 +01:00
|
|
|
];
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
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
|
|
|
|
''
|
2022-05-28 22:59:50 +01:00
|
|
|
table inet filter {
|
|
|
|
chain routing-tcp {
|
|
|
|
# Safe enough to allow all SSH
|
|
|
|
tcp dport ssh accept
|
2022-05-31 21:25:51 +01:00
|
|
|
|
2022-06-11 01:20:32 +01:00
|
|
|
${matchInet "tcp dport { http, https, 8448 } accept" "middleman"}
|
2022-05-31 21:25:51 +01:00
|
|
|
|
|
|
|
return
|
2022-05-28 22:59:50 +01:00
|
|
|
}
|
|
|
|
chain routing-udp {
|
2022-05-31 21:25:51 +01:00
|
|
|
return
|
2022-05-28 22:59:50 +01:00
|
|
|
}
|
|
|
|
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"}
|
2022-05-28 22:59:50 +01:00
|
|
|
}
|
2022-05-28 15:30:12 +01:00
|
|
|
chain postrouting {
|
2022-05-29 03:30:40 +01:00
|
|
|
ip saddr ${lib.my.colony.prefixes.all.v4} masquerade
|
2022-05-28 15:30:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
(mkIf config.my.build.isDevVM {
|
|
|
|
systemd.network = {
|
|
|
|
netdevs."05-dummy-base".netdevConfig = {
|
|
|
|
Name = "base";
|
|
|
|
Kind = "dummy";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|