-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.nix
executable file
·76 lines (64 loc) · 1.73 KB
/
example.nix
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{ config, pkgs, lib, ... }:
with lib;
let
netname = "retiolum";
cfg = config.networking.retiolum;
retiolum = pkgs.fetchgit {
url = "https://github.com/krebs/retiolum.git";
rev = "8edeafb01411943eb483b5431bccce6702406f12";
sha256 = "1vnmhr5qfxhndlnsk8c87qbbwmlph1inlj924vqymfm1lgsasdq0";
};
in {
options = {
networking.retiolum.ipv4 = mkOption {
type = with types; nullOr str;
description = ''
own ipv4 address
'';
default = null;
};
networking.retiolum.ipv6 = mkOption {
type = types.str;
description = ''
own ipv6 address
'';
};
networking.retiolum.nodename = mkOption {
type = types.str;
default = config.networking.hostName;
description = ''
tinc network name
'';
};
};
config = {
services.tinc.networks.${netname} = {
name = cfg.nodename;
extraConfig = ''
LocalDiscovery = yes
AutoConnect = yes
'';
};
systemd.services."tinc.${netname}" = {
preStart = ''
cp -R ${retiolum}/hosts /etc/tinc/retiolum/ || true
'';
};
networking.extraHosts = builtins.readFile (toString "${retiolum}/etc.hosts");
environment.systemPackages = [ config.services.tinc.networks.${netname}.package ];
networking.firewall.allowedTCPPorts = [ 655 ];
networking.firewall.allowedUDPPorts = [ 655 ];
#services.netdata.portcheck.checks.tinc.port = 655;
systemd.network.enable = true;
systemd.network.networks = {
"${netname}".extraConfig = ''
[Match]
Name = tinc.${netname}
[Network]
Address=${cfg.ipv6}/16
'' + optionalString (cfg.ipv4 != null) ''
Address=${cfg.ipv4}/12
'';
};
};
}