mirror of
https://gitlab.com/upRootNutrition/dotfiles.git
synced 2025-08-08 21:04:38 -05:00
feat: wireguard test
This commit is contained in:
parent
9c8890926e
commit
6fb7b5504d
7 changed files with 82 additions and 42 deletions
|
@ -28,7 +28,7 @@ in
|
||||||
options = ownerExclusiveReadWriteMask;
|
options = ownerExclusiveReadWriteMask;
|
||||||
};
|
};
|
||||||
wireguard = {
|
wireguard = {
|
||||||
ip0 = "10.100.0.1";
|
ip0 = "10.0.0.1";
|
||||||
};
|
};
|
||||||
storage0 = {
|
storage0 = {
|
||||||
mount = "/mnt/media/${ceresStorageDriveName}";
|
mount = "/mnt/media/${ceresStorageDriveName}";
|
||||||
|
|
|
@ -19,7 +19,7 @@ in
|
||||||
options = ownerWriteOthersReadMask;
|
options = ownerWriteOthersReadMask;
|
||||||
};
|
};
|
||||||
wireguard = {
|
wireguard = {
|
||||||
ip0 = "10.100.0.2";
|
ip0 = "10.0.0.2";
|
||||||
};
|
};
|
||||||
storage0 = {
|
storage0 = {
|
||||||
mount = "/mnt/media/games";
|
mount = "/mnt/media/games";
|
||||||
|
|
|
@ -14,7 +14,7 @@ in
|
||||||
path0 = "${sopsPath}/${name}";
|
path0 = "${sopsPath}/${name}";
|
||||||
};
|
};
|
||||||
ports = {
|
ports = {
|
||||||
port0 = 51820;
|
port0 = 53;
|
||||||
port1 = 51821;
|
port1 = 51821;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
11
modules/home/cli/utilities/ipTables/default.nix
Normal file
11
modules/home/cli/utilities/ipTables/default.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
home.packages = builtins.attrValues {
|
||||||
|
inherit (pkgs)
|
||||||
|
iptables
|
||||||
|
;
|
||||||
|
};
|
||||||
|
}
|
|
@ -18,7 +18,6 @@ in
|
||||||
wayland
|
wayland
|
||||||
searx
|
searx
|
||||||
flatpak
|
flatpak
|
||||||
wireGuard
|
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -33,7 +32,6 @@ in
|
||||||
sddm
|
sddm
|
||||||
flatpak
|
flatpak
|
||||||
espanso
|
espanso
|
||||||
wireGuard
|
|
||||||
glance
|
glance
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
@ -44,7 +42,6 @@ in
|
||||||
inherit (modules)
|
inherit (modules)
|
||||||
plasma
|
plasma
|
||||||
sddm
|
sddm
|
||||||
wireGuard
|
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -70,15 +67,6 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
mantle = {
|
|
||||||
imports = builtins.attrValues {
|
|
||||||
inherit (modules)
|
|
||||||
sops
|
|
||||||
xserver
|
|
||||||
;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
crust = {
|
crust = {
|
||||||
imports = builtins.attrValues {
|
imports = builtins.attrValues {
|
||||||
inherit (modules)
|
inherit (modules)
|
||||||
|
@ -88,6 +76,15 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mantle = {
|
||||||
|
imports = builtins.attrValues {
|
||||||
|
inherit (modules)
|
||||||
|
sops
|
||||||
|
xserver
|
||||||
|
;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
core = {
|
core = {
|
||||||
imports = builtins.attrValues {
|
imports = builtins.attrValues {
|
||||||
inherit (modules)
|
inherit (modules)
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
{ config, flake, ... }:
|
{
|
||||||
|
config,
|
||||||
|
flake,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
inherit (flake.config.services.instances) wireGuard;
|
inherit (flake.config.services.instances) wireGuard;
|
||||||
inherit (flake.config.machines.devices) mars ceres;
|
inherit (flake.config.machines.devices) mars ceres;
|
||||||
service = wireGuard;
|
service = wireGuard;
|
||||||
|
hostIP = "${ceres.wireguard.ip0}/24";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
networking = {
|
networking = {
|
||||||
firewall = {
|
firewall = {
|
||||||
|
allowedTCPPorts = [
|
||||||
|
service.ports.port0
|
||||||
|
];
|
||||||
allowedUDPPorts = [
|
allowedUDPPorts = [
|
||||||
53
|
|
||||||
service.ports.port0
|
service.ports.port0
|
||||||
service.ports.port1
|
service.ports.port1
|
||||||
];
|
];
|
||||||
interfaces.wg0.allowedTCPPorts = [
|
|
||||||
80
|
|
||||||
443
|
|
||||||
8888
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
nat = {
|
nat = {
|
||||||
|
@ -26,15 +29,36 @@ in
|
||||||
internalInterfaces = [ "wg0" ];
|
internalInterfaces = [ "wg0" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
wireguard.interfaces = {
|
wg-quick.interfaces = {
|
||||||
wg0 = {
|
wg0 = {
|
||||||
ips = [ "${ceres.wireguard.ip0}/24" ];
|
address = [
|
||||||
|
hostIP
|
||||||
|
"fdc9:281f:04d7:9ee9::1/64"
|
||||||
|
];
|
||||||
listenPort = service.ports.port1;
|
listenPort = service.ports.port1;
|
||||||
privateKeyFile = config.sops.secrets."${service.name}-private".path;
|
privateKeyFile = config.sops.secrets."${service.name}-private".path;
|
||||||
|
postUp = ''
|
||||||
|
${pkgs.iptables}/bin/iptables -A FORWARD -i wg0 -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s ${hostIP} -o eth0 -j MASQUERADE
|
||||||
|
${pkgs.iptables}/bin/ip6tables -A FORWARD -i wg0 -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/ip6tables -t nat -A POSTROUTING -s fdc9:281f:04d7:9ee9::1/64 -o eth0 -j MASQUERADE
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Undo the above
|
||||||
|
preDown = ''
|
||||||
|
${pkgs.iptables}/bin/iptables -D FORWARD -i wg0 -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s ${hostIP} -o eth0 -j MASQUERADE
|
||||||
|
${pkgs.iptables}/bin/ip6tables -D FORWARD -i wg0 -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/ip6tables -t nat -D POSTROUTING -s fdc9:281f:04d7:9ee9::1/64 -o eth0 -j MASQUERADE
|
||||||
|
'';
|
||||||
peers = [
|
peers = [
|
||||||
{
|
{
|
||||||
publicKey = "9zfRPxkxTLHM9tABC8lIaDMrzdjcF2l1mtG82uqGKUQ=";
|
publicKey = "9zfRPxkxTLHM9tABC8lIaDMrzdjcF2l1mtG82uqGKUQ=";
|
||||||
allowedIPs = [ "${mars.wireguard.ip0}/32" ];
|
presharedKeyFile = config.sops.secrets."${service.name}-mars-public".path;
|
||||||
|
allowedIPs = [
|
||||||
|
"${mars.wireguard.ip0}/32"
|
||||||
|
"fdc9:281f:04d7:9ee9::2/128"
|
||||||
|
];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -59,6 +83,7 @@ in
|
||||||
[
|
[
|
||||||
"private"
|
"private"
|
||||||
"public"
|
"public"
|
||||||
|
"mars-public"
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,17 +5,24 @@ let
|
||||||
service = wireGuard;
|
service = wireGuard;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
networking = {
|
networking.wg-quick.interfaces = {
|
||||||
wireguard.interfaces = {
|
|
||||||
wg0 = {
|
wg0 = {
|
||||||
ips = [ "${mars.wireguard.ip0}/24" ];
|
address = [
|
||||||
|
"${mars.wireguard.ip0}/24"
|
||||||
|
"fdc9:281f:04d7:9ee9::2/64"
|
||||||
|
];
|
||||||
|
dns = [
|
||||||
|
"${ceres.wireguard.ip0}"
|
||||||
|
"fdc9:281f:04d7:9ee9::1"
|
||||||
|
];
|
||||||
privateKeyFile = config.sops.secrets."${service.name}-mars-private".path;
|
privateKeyFile = config.sops.secrets."${service.name}-mars-private".path;
|
||||||
peers = [
|
peers = [
|
||||||
{
|
{
|
||||||
publicKey = "fs58+Kz+eG9qAXvvMB2NkW+wa88yP61uam4HHWaBJVw=";
|
publicKey = "fs58+Kz+eG9qAXvvMB2NkW+wa88yP61uam4HHWaBJVw=";
|
||||||
|
presharedKeyFile = config.sops.secrets."${service.name}-public".path;
|
||||||
allowedIPs = [
|
allowedIPs = [
|
||||||
"${ceres.wireguard.ip0}/32"
|
"0.0.0.0/0"
|
||||||
"192.168.1.0/24"
|
"::/0"
|
||||||
];
|
];
|
||||||
endpoint = "${web.remotehost.address0}:${builtins.toString service.ports.port1}";
|
endpoint = "${web.remotehost.address0}:${builtins.toString service.ports.port1}";
|
||||||
persistentKeepalive = 25;
|
persistentKeepalive = 25;
|
||||||
|
@ -23,7 +30,6 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
sops =
|
sops =
|
||||||
let
|
let
|
||||||
|
@ -43,6 +49,7 @@ in
|
||||||
[
|
[
|
||||||
"mars-private"
|
"mars-private"
|
||||||
"mars-public"
|
"mars-public"
|
||||||
|
"public"
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue