blob: 4beba7376ff3e82a2bba54dc8fa659d0d8cee7c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
{ 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;
defaultText = lib.literalExpression "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
'';
}));
};
}
|