From 663c4110fcb9fd21c9a8134ceb1b48ab3aa45a54 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 28 Oct 2017 23:42:44 +0200 Subject: tinc nmDispatch --- custom/tinc/def.nix | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'custom/tinc') diff --git a/custom/tinc/def.nix b/custom/tinc/def.nix index 5d1216c9..0fa0b912 100644 --- a/custom/tinc/def.nix +++ b/custom/tinc/def.nix @@ -76,6 +76,15 @@ let ''; }; + nmDispatch = mkOption { + type = types.bool; + default = config.networking.networkmanager.enable; + description = '' + Install a network-manager dispatcher script to automatically + connect to all remotes when networking is available + ''; + }; + }; in @@ -134,6 +143,21 @@ in } // data.interfaceConfig) ); + networking.networkmanager.dispatcherScripts = flip mapAttrs' cfg.networks (network: data: optional data.nmDispatch { + type = "basic"; + source = pkgs.writeScript "connectRemotes.sh" '' + #!${pkgs.stdenv.shell} + + shopt -s extglob + + case "''${2}" in + (?(vpn-)up) + systemctl --signal=ALRM --kill-who=main kill "tinc.${network}.service" + ;; + esac + ''; + }); + systemd.services = flip mapAttrs' cfg.networks (network: data: nameValuePair ("tinc.${network}") ({ -- cgit v1.2.3