Add wireguard VPN
This commit is contained in:
parent
120cec699d
commit
80a70002e9
2 changed files with 31 additions and 1 deletions
|
@ -3,8 +3,8 @@
|
||||||
imports = [
|
imports = [
|
||||||
./cloud.nix
|
./cloud.nix
|
||||||
./feedreader.nix
|
./feedreader.nix
|
||||||
|
./vpn.nix
|
||||||
#./dns.nix #TODO
|
#./dns.nix #TODO
|
||||||
#./feedreader.nix #TODO
|
|
||||||
#./wallabag.nix #TODO
|
#./wallabag.nix #TODO
|
||||||
#./id.nix #TODO
|
#./id.nix #TODO
|
||||||
#./mx.nix #TODO
|
#./mx.nix #TODO
|
||||||
|
|
30
host/montalin/applications/vpn.nix
Normal file
30
host/montalin/applications/vpn.nix
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{ config, pkgs, lib, ... }:
|
||||||
|
let
|
||||||
|
meta = import ../../../meta;
|
||||||
|
network = meta.network.virtual;
|
||||||
|
networkName = "mgmt";
|
||||||
|
networkConfig = network.${networkName};
|
||||||
|
hostName = config.networking.hostName;
|
||||||
|
in {
|
||||||
|
networking.wireguard.enable = true;
|
||||||
|
networking.wireguard.interfaces = {
|
||||||
|
"wg-${networkName}" = {
|
||||||
|
ips = [ "${networkConfig.hosts.${hostName}.v4.ip}/${toString networkConfig.v4.bitmask}" ];
|
||||||
|
privateKeyFile = "/secrets/wireguard/private/${networkName}";
|
||||||
|
generatePrivateKeyFile = true;
|
||||||
|
|
||||||
|
peers = let
|
||||||
|
reachablePeerHosts = lib.filterAttrs
|
||||||
|
(host: netconf: host != hostName && netconf.endpoint != null)
|
||||||
|
networkConfig.hosts;
|
||||||
|
in lib.mapAttrsToList (host: netconf: {
|
||||||
|
presharedKeyFile = netconf.presharedKeyFile or null; # Generate with wg genpsk
|
||||||
|
publicKey = netconf.publicKey;
|
||||||
|
endpoint = netconf.endpoint;
|
||||||
|
allowedIPs = [ netconf.v4.ip ];
|
||||||
|
persistantKeepalive = netconf.persistentKeepalive;
|
||||||
|
}) reachablePeerHosts;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue