blob: d50d899fc414179956eb7d3ea88c437067a47e6c (
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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
{
config,
lib,
pkgs,
...
}:
let
cfg = config.os.core.network;
in
{
options.os.core.network = {
enable = lib.mkEnableOption "system-wide networking setup";
profile = lib.mkOption {
type = lib.types.enum [
"client"
"server"
];
default = "client";
description = "Which networking profile configuration to apply";
};
lan = lib.mkOption {
description = "Physical Home Local Area Network configuration parameters.";
type = lib.types.submodule {
options = {
ip = lib.mkOption {
type = lib.types.str;
default = "10.0.0.2";
description = "The local static or leased IP assigned to this machine on the home network.";
};
range = lib.mkOption {
type = lib.types.str;
default = "10.0.0.0/8";
description = "The broader subnet block representing the physical home network.";
};
};
};
};
wg = lib.mkOption {
description = "Standard WireGuard VPN tunnel configuration parameters.";
type = lib.types.submodule {
options = {
ip = lib.mkOption {
type = lib.types.str;
default = "10.3.0.1";
description = "The explicit tunnel IP address assigned to this machine's WireGuard interface.";
};
range = lib.mkOption {
type = lib.types.str;
default = "10.3.0.0/24";
description = "The total addressable IP space assigned to the WireGuard network pool.";
};
};
};
};
hs = lib.mkOption {
description = "Headscale mesh overlay network configuration parameters.";
type = lib.types.submodule {
options = {
ip = lib.mkOption {
type = lib.types.str;
default = "10.4.0.1";
description = "The explicit mesh network IP address assigned to this machine via Headscale.";
};
range = lib.mkOption {
type = lib.types.str;
default = "10.4.0.0/24";
description = "The full mesh overlay allocation subnet block.";
};
};
};
};
};
config = lib.mkIf cfg.enable (
lib.mkMerge [
{
services.resolved.enable = true;
}
(lib.mkIf (cfg.profile == "client") {
networking.networkmanager = {
enable = true;
dns = "systemd-resolved";
wifi.macAddress = "random";
wifi.backend = "iwd";
ethernet.macAddress = "random";
};
systemd.services."NetworkManager-wait-online".enable = false;
environment.systemPackages = [
pkgs.impala
];
})
(lib.mkIf (cfg.profile == "server") {
networking = {
useNetworkd = true;
useDHCP = false;
};
systemd.network = {
enable = true;
netdevs."10-br-srv" = {
netdevConfig = {
Name = "br-srv";
Kind = "bridge";
};
};
networks."20-host-management" = {
matchConfig.Name = "br-srv";
address = [ "10.0.0.2/24" ];
gateway = [ "10.0.0.1" ];
networkConfig.LinkLocalAddressing = "no";
};
};
boot.kernel.sysctl = {
"net.ipv4.ip_nonlocal_bind" = 1;
};
})
]
);
}
|