imports = [
../profiles/dnscrypt-proxy2.nix
../profiles/security.nix
+ ../networking/wireguard/wg-intra.nix
oignon/hardware.nix
oignon/openvpn.nix
oignon/wireguard.nix
{ pkgs, lib, config, hostName, private, ... }:
-let
- domain = "sourcephile.fr";
- iface = "wg-intra";
- wg = config.networking.wireguard.interfaces.${iface};
- peer = {
- publicKey = "tE4fzqDrr7BgfOo9tWgGnpu3v0JRDEUZbJnm9e2F/GA=";
- allowedIPs = [ "192.168.42.3/32" ];
- };
- peers = {
- mermet = {
- publicKey = "XbTEP2X71LBTjmdmySdiOpQJ+uIomcXvg1aiQGUtWBI=";
- endpoint = "mermet.${domain}:43642";
- endpointsUpdater.enable = true;
- allowedIPs = [ "192.168.42.1/32" ];
- persistentKeepalive = 25;
- dynamicEndpointRefreshSeconds = 30 * 60;
- };
- losurdo = {
- publicKey = "xsFFep3k8z0pXgUOz4aryOF8l/KPBSOd4WQA26BkXy0=";
- #endpoint = "losurdo.${domain}:43642";
- allowedIPs = [ "192.168.42.2/32" ];
- persistentKeepalive = 5;
- };
- };
- keyToUnitName = lib.replaceChars
- [ "/" "-" " " "+" "=" ]
- [ "-" "\\x2d" "\\x20" "\\x2b" "\\x3d" ];
-in
{
-networking.firewall.extraCommands = ''
- ip46tables -A nixos-fw -i ${iface} -p tcp -m tcp --dport 22 -j ACCEPT
- ip46tables -A nixos-fw -i any -p udp -m udp --dport ${toString wg.listenPort} -j ACCEPT
-'';
-networking.wireguard.interfaces.${iface} = {
- ips = peer.allowedIPs;
- # Different from losurdo's listenPort to have them work behind the same NAT.
- listenPort = 43641;
- privateKeyFile = "${private}/${hostName}/wireguard/${iface}/privateKey";
- peers = lib.attrValues peers;
-};
-networking.hosts = builtins.listToAttrs (lib.concatLists (lib.attrValues (lib.mapAttrs (peerName: peer:
- map (ip: lib.nameValuePair (lib.removeSuffix "/32" ip) ["${peerName}.wg"]) peer.allowedIPs
- ) peers)));
+networking.hosts."192.168.42.2" = [
+ "sourcephile.wg"
+ "builds.sourcephile.wg"
+ "dispatch.sourcephile.wg"
+ "git.sourcephile.wg"
+ "hg.sourcephile.wg"
+ "hub.sourcephile.wg"
+ "lists.sourcephile.wg"
+ "man.sourcephile.wg"
+ "meta.sourcephile.wg"
+ "pages.sourcephile.wg"
+ "paste.sourcephile.wg"
+ "todo.sourcephile.wg"
+];
/*
systemd.services =
{
imports = [
../profiles/dnscrypt-proxy2.nix
../profiles/security.nix
+ ../networking/wireguard/wg-intra.nix
patate/backup.nix
patate/hardware.nix
- patate/wireguard.nix
];
home-manager.users.sevy = {
+++ /dev/null
-{ pkgs, lib, config, hostName, private, ... }:
-let
- domain = "sourcephile.fr";
- iface = "wg-intra";
- wg = config.networking.wireguard.interfaces.${iface};
- peer = {
- publicKey = "tE4fzqDrr7BgfOo9tWgGnpu3v0JRDEUZbJnm9e2F/GA=";
- allowedIPs = [ "192.168.42.4/32" ];
- };
- peers = {
- mermet = {
- publicKey = "XbTEP2X71LBTjmdmySdiOpQJ+uIomcXvg1aiQGUtWBI=";
- endpoint = "mermet.${domain}:43642";
- endpointsUpdater.enable = true;
- allowedIPs = [ "192.168.42.1/32" ];
- persistentKeepalive = 25;
- dynamicEndpointRefreshSeconds = 30 * 60;
- };
- losurdo = {
- publicKey = "xsFFep3k8z0pXgUOz4aryOF8l/KPBSOd4WQA26BkXy0=";
- #endpoint = "losurdo.${domain}:43642";
- allowedIPs = [ "192.168.42.2/32" ];
- persistentKeepalive = 5;
- };
- };
- keyToUnitName = lib.replaceChars
- [ "/" "-" " " "+" "=" ]
- [ "-" "\\x2d" "\\x20" "\\x2b" "\\x3d" ];
-in
-{
-networking.firewall.extraCommands = ''
- ip46tables -A nixos-fw -i ${iface} -p tcp -m tcp --dport 22 -j ACCEPT
- ip46tables -A nixos-fw -i any -p udp -m udp --dport ${toString wg.listenPort} -j ACCEPT
-'';
-networking.wireguard.interfaces.${iface} = {
- ips = peer.allowedIPs;
- # Different from losurdo's listenPort to have them work behind the same NAT.
- listenPort = 43644;
- privateKeyFile = "${private}/${hostName}/wireguard/${iface}/privateKey";
- peers = lib.attrValues peers;
-};
-networking.hosts = builtins.listToAttrs (lib.concatLists (lib.attrValues (lib.mapAttrs (peerName: peer:
- map (ip: lib.nameValuePair (lib.removeSuffix "/32" ip) ["${peerName}.wg"]) peer.allowedIPs
- ) peers)));
-/*
-systemd.services =
- {
- openssh = {
- after = ["wireguard-${iface}.service"];
- serviceConfig.Restart = "on-failure";
- };
- };
-services.openssh.listenAddresses = map (ip: {addr=lib.removeSuffix "/32" ip;}) peer.allowedIPs;
-*/
-}
--- /dev/null
+{ pkgs, lib, config, hostName, private, ... }:
+let
+ iface = "wg-intra";
+ hosts = import wg-intra/hosts.nix;
+ wg = config.networking.wireguard.interfaces.${iface};
+in
+{
+networking.wireguard.interfaces.${iface} = lib.recursiveUpdate
+ (removeAttrs hosts.${hostName} ["ipv4" "persistentKeepalive" "peer"])
+ {
+ peers =
+ lib.mapAttrsToList (peerName: peer: lib.recursiveUpdate
+ { persistentKeepalive = hosts.${hostName}.persistentKeepalive or null; }
+ peer.peer
+ ) (removeAttrs hosts [hostName]);
+ privateKeyFile = "${private}/${hostName}/wireguard/${iface}/privateKey";
+ };
+networking.hosts = lib.mkMerge [
+ (lib.mapAttrs' (hostName: host:
+ lib.nameValuePair host.ipv4 [ "${hostName}.wg" ]) hosts)
+ { "${hosts.losurdo.ipv4}" = [
+ "nix-extracache.losurdo.wg"
+ "nix-localcache.losurdo.wg"
+ ]; }
+];
+networking.firewall.extraCommands = ''
+ ip46tables -A nixos-fw -i ${iface} -p tcp -m tcp --dport 22 -j ACCEPT
+ ip46tables -A nixos-fw -i any -p udp -m udp --dport ${toString wg.listenPort} -j ACCEPT
+'';
+services.fail2ban.ignoreIP = lib.concatMap
+ (host: host.peer.allowedIPs)
+ (lib.attrValues hosts);
+}
--- /dev/null
+{
+ mermet = rec {
+ ipv4 = "192.168.42.1";
+ ips = ["${ipv4}/24"];
+ listenPort = 43642;
+ peersAnnouncing.enable = true;
+ peer = {
+ publicKey = "XbTEP2X71LBTjmdmySdiOpQJ+uIomcXvg1aiQGUtWBI=";
+ allowedIPs = [ "${ipv4}/32" ];
+ endpoint = "80.67.180.129:${toString listenPort}";
+ endpointsUpdater.enable = true;
+ };
+ };
+ losurdo = rec {
+ ipv4 = "192.168.42.2";
+ ips = ["${ipv4}/24"];
+ listenPort = 43643;
+ persistentKeepalive = 5;
+ peer = {
+ publicKey = "xsFFep3k8z0pXgUOz4aryOF8l/KPBSOd4WQA26BkXy0=";
+ allowedIPs = [ "${ipv4}/32" ];
+ };
+ };
+ oignon = rec {
+ ipv4 = "192.168.42.3";
+ ips = ["${ipv4}/24"];
+ #persistentKeepalive = 10;
+ peer = {
+ publicKey = "tE4fzqDrr7BgfOo9tWgGnpu3v0JRDEUZbJnm9e2F/GA=";
+ allowedIPs = [ "${ipv4}/32" ];
+ #persistentKeepalive = 25;
+ #dynamicEndpointRefreshSeconds = 60;
+ };
+ };
+ patate = rec {
+ ipv4 = "192.168.42.4";
+ ips = ["${ipv4}/24"];
+ #persistentKeepalive = 10;
+ peer = {
+ publicKey = "gaEz7nvJTk4h3DGOpeZXSWmYDDrc5xQkuJ28sGrksx4=";
+ allowedIPs = [ "${ipv4}/32" ];
+ #persistentKeepalive = 25;
+ #dynamicEndpointRefreshSeconds = 60;
+ };
+ };
+}