Compare commits
No commits in common. "c16d8513d226a386624988a063f62e0bfa170b0b" and "3862992b76b9672d5ec26172c374b31ebc8f3689" have entirely different histories.
c16d8513d2
...
3862992b76
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1,3 +1,4 @@
|
||||||
secrets/**/*.secret filter=git-crypt diff=git-crypt
|
secrets/**/*.secret filter=git-crypt diff=git-crypt
|
||||||
secrets/matrix-email-config.nix filter=git-crypt diff=git-crypt
|
secrets/matrix-email-config.nix filter=git-crypt diff=git-crypt
|
||||||
|
secrets/wireguard.nix filter=git-crypt diff=git-crypt
|
||||||
home/secrets/*.secret filter=git-crypt diff=git-crypt
|
home/secrets/*.secret filter=git-crypt diff=git-crypt
|
||||||
|
|
|
@ -42,3 +42,5 @@ RSS reader
|
||||||
Grafana and Prometheus are currently used as a glorified =htop=.
|
Grafana and Prometheus are currently used as a glorified =htop=.
|
||||||
|
|
||||||
** Nextcloud
|
** Nextcloud
|
||||||
|
|
||||||
|
** Wireguard VPN
|
||||||
|
|
|
@ -32,6 +32,11 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.tailscale = {
|
||||||
|
enable = true;
|
||||||
|
package = pkgs.unstable.tailscale;
|
||||||
|
};
|
||||||
|
|
||||||
networking.hostName = "boreal"; # Define your hostname.
|
networking.hostName = "boreal"; # Define your hostname.
|
||||||
networking.domain = "alarsyo.net";
|
networking.domain = "alarsyo.net";
|
||||||
|
|
||||||
|
@ -82,7 +87,22 @@ in
|
||||||
|
|
||||||
pipewire.enable = true;
|
pipewire.enable = true;
|
||||||
|
|
||||||
tailscale.enable = true;
|
wireguard = {
|
||||||
|
enable = false;
|
||||||
|
iface = "wg";
|
||||||
|
port = 51820;
|
||||||
|
|
||||||
|
net = {
|
||||||
|
v4 = {
|
||||||
|
subnet = "10.0.0";
|
||||||
|
mask = 24;
|
||||||
|
};
|
||||||
|
v6 = {
|
||||||
|
subnet = "fd42:42:42";
|
||||||
|
mask = 64;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
|
|
|
@ -21,6 +21,11 @@ in
|
||||||
|
|
||||||
boot.supportedFilesystems = [ "btrfs" ];
|
boot.supportedFilesystems = [ "btrfs" ];
|
||||||
|
|
||||||
|
boot.kernel.sysctl = {
|
||||||
|
"net.ipv6.conf.all.forwarding" = true;
|
||||||
|
"net.ipv4.ip_forward" = true;
|
||||||
|
};
|
||||||
|
|
||||||
services.btrfs = {
|
services.btrfs = {
|
||||||
autoScrub = {
|
autoScrub = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
@ -28,6 +33,18 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.tailscale = {
|
||||||
|
enable = true;
|
||||||
|
package = pkgs.unstable.tailscale;
|
||||||
|
};
|
||||||
|
systemd.services.tailscaled = {
|
||||||
|
path = [ pkgs.procps ];
|
||||||
|
};
|
||||||
|
networking.firewall = {
|
||||||
|
trustedInterfaces = [ "tailscale0" ];
|
||||||
|
allowedUDPPorts = [ config.services.tailscale.port ];
|
||||||
|
};
|
||||||
|
|
||||||
virtualisation.docker = {
|
virtualisation.docker = {
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
@ -123,8 +140,6 @@ in
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
tailscale.enable = true;
|
|
||||||
|
|
||||||
tgv = {
|
tgv = {
|
||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
@ -134,6 +149,23 @@ in
|
||||||
username = "alarsyo";
|
username = "alarsyo";
|
||||||
password = secrets.transmission-password;
|
password = secrets.transmission-password;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
wireguard = {
|
||||||
|
enable = true;
|
||||||
|
iface = "wg";
|
||||||
|
port = 51820;
|
||||||
|
|
||||||
|
net = {
|
||||||
|
v4 = {
|
||||||
|
subnet = "10.0.0";
|
||||||
|
mask = 24;
|
||||||
|
};
|
||||||
|
v6 = {
|
||||||
|
subnet = "fd42:42:42";
|
||||||
|
mask = 64;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Enable the OpenSSH daemon.
|
# Enable the OpenSSH daemon.
|
||||||
|
|
|
@ -18,6 +18,8 @@ with lib;
|
||||||
|
|
||||||
borg-backup = import ./borg-backup { inherit lib; };
|
borg-backup = import ./borg-backup { inherit lib; };
|
||||||
|
|
||||||
|
wireguard = pkgs.callPackage ./wireguard.nix { };
|
||||||
|
|
||||||
matrixEmailConfig = import ./matrix-email-config.nix;
|
matrixEmailConfig = import ./matrix-email-config.nix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
BIN
secrets/wireguard.nix
Normal file
BIN
secrets/wireguard.nix
Normal file
Binary file not shown.
|
@ -19,8 +19,8 @@
|
||||||
./pipewire.nix
|
./pipewire.nix
|
||||||
./postgresql-backup.nix
|
./postgresql-backup.nix
|
||||||
./postgresql.nix
|
./postgresql.nix
|
||||||
./tailscale.nix
|
|
||||||
./tgv.nix
|
./tgv.nix
|
||||||
./transmission.nix
|
./transmission.nix
|
||||||
|
./wireguard.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
{ config, lib, pkgs, ... }:
|
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
|
||||||
cfg = config.my.services.tailscale;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.my.services.tailscale = {
|
|
||||||
enable = lib.mkEnableOption "Tailscale";
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
services.tailscale = {
|
|
||||||
enable = true;
|
|
||||||
package = pkgs.unstable.tailscale;
|
|
||||||
};
|
|
||||||
|
|
||||||
# FIXME: remove when upgrading to 21.11, added to module by default
|
|
||||||
systemd.services.tailscaled = {
|
|
||||||
path = [ pkgs.procps ];
|
|
||||||
};
|
|
||||||
|
|
||||||
networking.firewall = {
|
|
||||||
trustedInterfaces = [ "tailscale0" ];
|
|
||||||
allowedUDPPorts = [ config.services.tailscale.port ];
|
|
||||||
};
|
|
||||||
|
|
||||||
# enable IP forwarding to use as exit node
|
|
||||||
boot.kernel.sysctl = {
|
|
||||||
"net.ipv6.conf.all.forwarding" = true;
|
|
||||||
"net.ipv4.ip_forward" = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
122
services/wireguard.nix
Normal file
122
services/wireguard.nix
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
# Stolen from:
|
||||||
|
#
|
||||||
|
# https://gitea.belanyi.fr/ambroisie/nix-config/src/branch/main/services/wireguard.nix
|
||||||
|
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.my.services.wireguard;
|
||||||
|
hostName = config.networking.hostName;
|
||||||
|
|
||||||
|
peers = config.my.secrets.wireguard.peers;
|
||||||
|
thisPeer = peers."${hostName}";
|
||||||
|
otherPeers = lib.filterAttrs (name: _: name != hostName) peers;
|
||||||
|
|
||||||
|
extIface = config.my.networking.externalInterface;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.my.services.wireguard = with lib; {
|
||||||
|
enable = mkEnableOption "Wireguard VPN service";
|
||||||
|
|
||||||
|
iface = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "wg";
|
||||||
|
example = "wg0";
|
||||||
|
description = "Name of the interface to configure";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
type = types.port;
|
||||||
|
default = 51820;
|
||||||
|
example = 55555;
|
||||||
|
description = "Port to configure for Wireguard";
|
||||||
|
};
|
||||||
|
|
||||||
|
net = {
|
||||||
|
v4 = {
|
||||||
|
subnet = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "10.0.0";
|
||||||
|
example = "10.100.0";
|
||||||
|
description = "Which prefix to use for internal IPs";
|
||||||
|
};
|
||||||
|
mask = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 24;
|
||||||
|
example = 28;
|
||||||
|
description = "The CIDR mask to use on internal IPs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
v6 = {
|
||||||
|
subnet = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "fd42:42:42";
|
||||||
|
example = "fdc9:281f:04d7:9ee9";
|
||||||
|
description = "Which prefix to use for internal IPs";
|
||||||
|
};
|
||||||
|
mask = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 64;
|
||||||
|
example = 68;
|
||||||
|
description = "The CIDR mask to use on internal IPs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config.networking = lib.mkIf cfg.enable {
|
||||||
|
wg-quick.interfaces."${cfg.iface}" = {
|
||||||
|
listenPort = cfg.port;
|
||||||
|
address = with cfg.net; with lib; [
|
||||||
|
"${v4.subnet}.${toString thisPeer.clientNum}/${toString v4.mask}"
|
||||||
|
"${v6.subnet}::${toString thisPeer.clientNum}/${toHexString v6.mask}"
|
||||||
|
];
|
||||||
|
privateKey = thisPeer.privateKey;
|
||||||
|
|
||||||
|
peers = lib.mapAttrsToList
|
||||||
|
(name: peer: {
|
||||||
|
inherit (peer) publicKey;
|
||||||
|
} // lib.optionalAttrs (thisPeer ? externalIp) {
|
||||||
|
# Only forward from server to clients
|
||||||
|
allowedIPs = with cfg.net; [
|
||||||
|
"${v4.subnet}.${toString peer.clientNum}/32"
|
||||||
|
"${v6.subnet}::${toString peer.clientNum}/128"
|
||||||
|
];
|
||||||
|
} // lib.optionalAttrs (peer ? externalIp) {
|
||||||
|
# Known addresses
|
||||||
|
endpoint = "${peer.externalIp}:${toString cfg.port}";
|
||||||
|
} // lib.optionalAttrs (!(thisPeer ? externalIp)) {
|
||||||
|
# Forward all traffic to server
|
||||||
|
allowedIPs = with cfg.net; [
|
||||||
|
"0.0.0.0/0"
|
||||||
|
"::/0"
|
||||||
|
];
|
||||||
|
# Roaming clients need to keep NAT-ing active
|
||||||
|
persistentKeepalive = 10;
|
||||||
|
})
|
||||||
|
otherPeers;
|
||||||
|
} // lib.optionalAttrs (thisPeer ? externalIp) {
|
||||||
|
# Setup forwarding on server
|
||||||
|
postUp = with cfg.net; ''
|
||||||
|
${pkgs.iptables}/bin/iptables -A FORWARD -i ${cfg.iface} -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s ${v4.subnet}.1/${toString v4.mask} -o ${extIface} -j MASQUERADE
|
||||||
|
${pkgs.iptables}/bin/ip6tables -A FORWARD -i ${cfg.iface} -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/ip6tables -t nat -A POSTROUTING -s ${v6.subnet}::1/${toString v6.mask} -o ${extIface} -j MASQUERADE
|
||||||
|
'';
|
||||||
|
preDown = with cfg.net; ''
|
||||||
|
${pkgs.iptables}/bin/iptables -D FORWARD -i ${cfg.iface} -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s ${v4.subnet}.1/${toString v4.mask} -o ${extIface} -j MASQUERADE
|
||||||
|
${pkgs.iptables}/bin/ip6tables -D FORWARD -i ${cfg.iface} -j ACCEPT
|
||||||
|
${pkgs.iptables}/bin/ip6tables -t nat -D POSTROUTING -s ${v6.subnet}::1/${toString v6.mask} -o ${extIface} -j MASQUERADE
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
nat = lib.optionalAttrs (thisPeer ? externalIp) {
|
||||||
|
enable = true;
|
||||||
|
externalInterface = extIface;
|
||||||
|
internalInterfaces = [ cfg.iface ];
|
||||||
|
};
|
||||||
|
|
||||||
|
firewall.allowedUDPPorts = lib.optional (thisPeer ? externalIp) cfg.port;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue