From 8b6bc354bdb8d1bc7e132c65a8d734cc74266c63 Mon Sep 17 00:00:00 2001 From: Zuckerberg Date: Tue, 7 Mar 2023 22:54:26 -0700 Subject: [PATCH] Peer to peer connection keepalive task --- common/network/default.nix | 1 + common/network/hosts.nix | 32 ++++++++++++++++++-------------- common/network/zerotier.nix | 2 ++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/common/network/default.nix b/common/network/default.nix index 70529e7..49581e4 100644 --- a/common/network/default.nix +++ b/common/network/default.nix @@ -9,6 +9,7 @@ in imports = [ ./hosts.nix ./pia-openvpn.nix + ./ping.nix ./tailscale.nix ./vpn.nix ./zerotier.nix diff --git a/common/network/hosts.nix b/common/network/hosts.nix index 364a626..3438a2c 100644 --- a/common/network/hosts.nix +++ b/common/network/hosts.nix @@ -3,6 +3,10 @@ with builtins; let + # TODO: remove when all systems are updated to new enough nixpkgs + concatMapAttrs = + f: with lib; flip pipe [ (mapAttrs f) attrValues (foldl' mergeAttrs { }) ]; + system = (import ../ssh.nix).system; # hostnames that resolve on clearnet for LUKS unlocking @@ -18,13 +22,18 @@ let ponyo = "cfamr6artx75qvt7ho3rrbsc7mkucmv5aawebwflsfuorusayacffryd.onion"; s0 = "r3zvf7f2ppaeithzswigma46pajt3hqytmkg3rshgknbl3jbni455fqd.onion"; }; -in { - networking.hosts = { - # some DNS providers filter local ip results from DNS request - "172.30.145.180" = [ "s0.zt.neet.dev" ]; - "172.30.109.9" = [ "ponyo.zt.neet.dev" ]; - "172.30.189.212" = [ "ray.zt.neet.dev" ]; + + zerotierHosts = { + "s0.zt.neet.dev" = "172.30.145.180"; + "ponyo.zt.neet.dev" = "172.30.109.9"; + "ray.zt.neet.dev" = "172.30.189.212"; }; +in { + # some DNS providers filter local ip results from DNS request + networking.hosts = concatMapAttrs (host: ip: {ip = [host];}) zerotierHosts; + + # TODO only add if zerotier is enabled + keepalive-ping.hosts = attrNames zerotierHosts; programs.ssh.knownHosts = { liza = { @@ -95,12 +104,7 @@ in { # prebuilt cmds for easy ssh LUKS unlock environment.shellAliases = - let - # TODO: remove when all systems are updated to new enough nixpkgs - concatMapAttrs = - f: with lib; flip pipe [ (mapAttrs f) attrValues (foldl' mergeAttrs { }) ]; - in - concatMapAttrs (host: addr: {"unlock-over-tor_${host}" = "torsocks ssh root@${addr}";}) unlock-onion-hosts - // - concatMapAttrs (host: addr: {"unlock_${host}" = "torsocks ssh root@${addr}";}) unlock-clearnet-hosts; + concatMapAttrs (host: addr: {"unlock-over-tor_${host}" = "torsocks ssh root@${addr}";}) unlock-onion-hosts + // + concatMapAttrs (host: addr: {"unlock_${host}" = "torsocks ssh root@${addr}";}) unlock-clearnet-hosts; } \ No newline at end of file diff --git a/common/network/zerotier.nix b/common/network/zerotier.nix index cbbde1b..dd8fc2c 100644 --- a/common/network/zerotier.nix +++ b/common/network/zerotier.nix @@ -4,6 +4,8 @@ let cfg = config.services.zerotierone; in { config = lib.mkIf cfg.enable { + keepalive-ping.enable = true; + services.zerotierone.joinNetworks = [ "565799d8f6d654c0" ];