Add haproxy/mmproxy combo

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-03-01 23:02:03 +00:00
parent ae66cfd854
commit a271e892c3
7 changed files with 101 additions and 41 deletions

View File

@@ -0,0 +1,26 @@
{ ... }:
{
# TODO: Some way to automatically configure?
services.haproxy = {
enable = true;
config = ''
global
maxconn 4096
defaults
mode tcp
timeout connect 5s
timeout client 30s
timeout server 30s
frontend http
bind *:80
bind *:443
default_backend main
backend main
server jupiter 10.0.0.2:80 send-proxy-v2
server jupiter_ssl 10.0.0.2:443 send-proxy-v2
'';
};
}

View File

@@ -1,12 +1,6 @@
{
config,
inputs,
pkgs,
...
}:
{ config, inputs, ... }:
let
jupiterConfig = inputs.self.nixosConfigurations.jupiter.config;
publicInterface = "ens3";
wireguardPort = 51820;
in
{
@@ -20,40 +14,18 @@ in
allowedUDPPorts = [ wireguardPort ] ++ jupiterConfig.networking.firewall.allowedUDPPorts;
};
wireguard.interfaces.wg0 =
let
iptables = "${pkgs.iptables}/bin/iptables";
in
rec {
ips = [ "10.0.0.1/24" ];
listenPort = wireguardPort;
privateKeyFile = config.sops.secrets."wireguard".path;
wireguard.interfaces.wg0 = {
ips = [ "10.0.0.1/24" ];
listenPort = wireguardPort;
privateKeyFile = config.sops.secrets."wireguard".path;
postSetup = [
"${iptables} -t nat -A PREROUTING -i ${publicInterface} -p tcp --dport ${builtins.toString (builtins.elemAt config.services.openssh.ports 0)} -j RETURN"
"${iptables} -t nat -A PREROUTING -i ${publicInterface} -p udp --dport ${builtins.toString listenPort} -j RETURN"
"${iptables} -t nat -A PREROUTING -i ${publicInterface} -j DNAT --to-destination 10.0.0.2"
"${iptables} -t nat -A POSTROUTING -d 10.0.0.2 -p tcp --dport ${builtins.toString (builtins.elemAt config.services.openssh.ports 0)} -j RETURN"
"${iptables} -t nat -A POSTROUTING -d 10.0.0.2 -p udp --dport ${builtins.toString listenPort} -j RETURN"
"${iptables} -t nat -A POSTROUTING -d 10.0.0.2 -j SNAT --to-source 10.0.0.1"
];
postShutdown = [
"${iptables} -t nat -D PREROUTING -i ${publicInterface} -p tcp --dport ${builtins.toString (builtins.elemAt config.services.openssh.ports 0)} -j RETURN"
"${iptables} -t nat -D PREROUTING -i ${publicInterface} -p udp --dport ${builtins.toString listenPort} -j RETURN"
"${iptables} -t nat -D PREROUTING -i ${publicInterface} -j DNAT --to-destination 10.0.0.2"
"${iptables} -t nat -D POSTROUTING -d 10.0.0.2 -p tcp --dport ${builtins.toString (builtins.elemAt config.services.openssh.ports 0)} -j RETURN"
"${iptables} -t nat -D POSTROUTING -d 10.0.0.2 -p udp --dport ${builtins.toString listenPort} -j RETURN"
"${iptables} -t nat -D POSTROUTING -d 10.0.0.2 -j SNAT --to-source 10.0.0.1"
];
peers = [
{
name = "jupiter";
allowedIPs = [ "10.0.0.2/32" ];
publicKey = "Lvx7bpyqI8rUrxYVDolz7T+EPuRWDohJAAToq7kH7EU=";
}
];
};
peers = [
{
name = "jupiter";
allowedIPs = [ "10.0.0.2/32" ];
publicKey = "Lvx7bpyqI8rUrxYVDolz7T+EPuRWDohJAAToq7kH7EU=";
}
];
};
};
}

View File

@@ -7,6 +7,7 @@
./hardware
../common/configs/system/impermanence
../common/configs/system/neovim
../common/configs/system/nix
../common/configs/system/nixpkgs
../common/configs/system/sops
@@ -16,6 +17,7 @@
../common/configs/system/zsh
./configs/boot
./configs/haproxy
./configs/sshd
./configs/wireguard
];