From f6e600c20d6a97ebeda23fa2bb5621646222b2b0 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 2 Jan 2021 20:53:17 +0100 Subject: sif: import config --- modules/tinc-networkmanager.nix | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 modules/tinc-networkmanager.nix (limited to 'modules/tinc-networkmanager.nix') diff --git a/modules/tinc-networkmanager.nix b/modules/tinc-networkmanager.nix new file mode 100644 index 00000000..ff03abd2 --- /dev/null +++ b/modules/tinc-networkmanager.nix @@ -0,0 +1,36 @@ +{ lib, config, pkgs, ... }: +let + cfg = config.services.tinc; +in { + options = { + services.tinc.networks = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule { + options.nmDispatch = lib.mkOption { + type = lib.types.bool; + default = config.networking.networkmanager.enable; + description = '' + Install a network-manager dispatcher script to automatically + connect to all remotes when networking is available + ''; + }; + }); + }; + }; + + config = { + networking.networkmanager.dispatcherScripts = lib.concatLists (lib.flip lib.mapAttrsToList cfg.networks (network: data: lib.optional data.nmDispatch { + type = "basic"; + source = pkgs.writeScript "connect-${network}.sh" '' + #!${pkgs.stdenv.shell} + + shopt -s extglob + + case "''${2}" in + (?(vpn-)up) + ${data.package}/bin/tinc -n ${network} --pidfile /run/tinc.${network}.pid --batch retry + ;; + esac + ''; + })); + }; +} -- cgit v1.2.3