]> Git — Sourcephile - julm/julm-nix.git/blob - hosts/aubergine/networking.nix
aubergine: enable tmpOnTmpfs
[julm/julm-nix.git] / hosts / aubergine / networking.nix
1 { config, pkgs, lib, hostName, ... }:
2 let
3 wifiIface = "wlp5s0";
4 wwanIface = "wwp0s19u1u3i3"; # usb_modeswitch -W -v 12d1 -p 1573 -u 1
5 ftthIface = "enp1s0";
6 eth1Iface = "enp2s0";
7 eth2Iface = "enp3s0";
8 eth3Iface = "enp4s0";
9 wifiIPv4 = "192.168.5";
10 eth1IPv4 = "192.168.2";
11 eth2IPv4 = "192.168.3";
12 eth3IPv4 = "192.168.4";
13 in
14 {
15 imports = [
16 networking/nftables.nix
17 ../../nixos/profiles/networking.nix
18 ../../nixos/profiles/dnscrypt-proxy2.nix
19 ../../nixos/profiles/wireguard/wg-intra.nix
20 ];
21 install.substituteOnDestination = false;
22 networking.domain = "sourcephile.fr";
23 networking.useDHCP = false;
24
25 boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
26 networking.nftables.ruleset = lib.mkAfter ''
27 table inet filter {
28 chain input {
29 iifname { ${wwanIface}, ${ftthIface} } jump input-net
30 iifname { ${wwanIface}, ${ftthIface} } log level warn prefix "input-net: " counter drop
31
32 iifname { ${wifiIface}, ${eth1Iface}, ${eth2Iface}, ${eth3Iface} } jump input-lan
33 iifname { ${wifiIface}, ${eth1Iface}, ${eth2Iface}, ${eth3Iface} } log level warn prefix "input-lan: " counter drop
34 }
35 chain output {
36 oifname { ${wwanIface}, ${ftthIface} } jump output-net
37 oifname { ${wwanIface}, ${ftthIface} } log level warn prefix "output-net: " counter drop
38
39 oifname { ${wifiIface}, ${eth1Iface}, ${eth2Iface}, ${eth3Iface} } jump output-lan
40 oifname { ${wifiIface}, ${eth1Iface}, ${eth2Iface}, ${eth3Iface} } log level warn prefix "output-lan: " counter drop
41 }
42 chain forward-to-net {
43 #jump forward-connectivity
44 counter accept
45 }
46 chain forward-from-net {
47 ct state { established, related } accept
48 log level warn prefix "forward-from-net: " counter drop
49 }
50 chain forward {
51 iifname { ${wifiIface}, ${eth1Iface}, ${eth2Iface}, ${eth3Iface} } oifname { ${wwanIface}, ${ftthIface} } goto forward-to-net
52 iifname { ${wwanIface}, ${ftthIface} } oifname { ${wifiIface}, ${eth1Iface}, ${eth2Iface}, ${eth3Iface} } goto forward-from-net
53 log level warn prefix "forward: " counter drop
54 }
55 }
56 table inet nat {
57 chain postrouting {
58 iifname { ${wifiIface}, ${eth1Iface}, ${eth2Iface}, ${eth3Iface} } oifname { ${wwanIface}, ${ftthIface} } masquerade
59 }
60 }
61 '';
62
63 services.avahi.openFirewall = true;
64 services.dnscrypt-proxy2.settings.listen_addresses = [
65 "127.0.0.1:53"
66 "[::1]:53"
67 "${wifiIPv4}.1:53"
68 "${eth1IPv4}.1:53"
69 "${eth2IPv4}.1:53"
70 "${eth3IPv4}.1:53"
71 ];
72 networking.interfaces = {
73 ${ftthIface} = {
74 useDHCP = false;
75 };
76 ${wifiIface} = {
77 useDHCP = false;
78 ipv4.addresses = [ { address = "${wifiIPv4}.1"; prefixLength = 24; } ];
79 };
80 ${eth1Iface} = {
81 useDHCP = false;
82 ipv4.addresses = [ { address = "${eth1IPv4}.1"; prefixLength = 24; } ];
83 };
84 ${eth2Iface} = {
85 useDHCP = false;
86 ipv4.addresses = [ { address = "${eth2IPv4}.1"; prefixLength = 24; } ];
87 };
88 ${eth3Iface} = {
89 useDHCP = false;
90 ipv4.addresses = [ { address = "${eth3IPv4}.1"; prefixLength = 24; } ];
91 };
92 };
93
94
95 systemd.services.dhcpd4 = {
96 onFailure = [
97 "network-addresses-${wifiIface}.service"
98 "network-addresses-${eth1Iface}.service"
99 "network-addresses-${eth2Iface}.service"
100 "network-addresses-${eth3Iface}.service"
101 ];
102 };
103 services.dhcpd4 = {
104 enable = true;
105 interfaces = [
106 wifiIface
107 eth1Iface
108 eth2Iface
109 eth3Iface
110 ];
111 extraConfig = ''
112 option subnet-mask 255.255.255.0;
113
114 option broadcast-address ${wifiIPv4}.255;
115 option routers ${wifiIPv4}.1;
116 option domain-name-servers ${wifiIPv4}.1;
117 subnet ${wifiIPv4}.0 netmask 255.255.255.0 {
118 range ${wifiIPv4}.100 ${wifiIPv4}.200;
119 }
120
121 option broadcast-address ${eth1IPv4}.255;
122 option routers ${eth1IPv4}.1;
123 option domain-name-servers ${eth1IPv4}.1;
124 subnet ${eth1IPv4}.0 netmask 255.255.255.0 {
125 range ${eth1IPv4}.100 ${eth1IPv4}.200;
126 }
127
128 option broadcast-address ${eth2IPv4}.255;
129 option routers ${eth2IPv4}.1;
130 option domain-name-servers ${eth2IPv4}.1;
131 subnet ${eth2IPv4}.0 netmask 255.255.255.0 {
132 range ${eth2IPv4}.100 ${eth2IPv4}.200;
133 }
134
135 option broadcast-address ${eth3IPv4}.255;
136 option routers ${eth3IPv4}.1;
137 option domain-name-servers ${eth3IPv4}.1;
138 subnet ${eth3IPv4}.0 netmask 255.255.255.0 {
139 range ${eth3IPv4}.100 ${eth3IPv4}.200;
140 }
141 '';
142 };
143
144 systemd.services.NetworkManager.wants = [ "ModemManager.service" ];
145 networking.networkmanager = {
146 #enable = true;
147 unmanaged = [
148 ftthIface
149 wifiIface
150 eth1Iface
151 eth2Iface
152 eth3Iface
153 ];
154 };
155 environment.etc."NetworkManager/system-connections/Prixtel.nmconnection" = {
156 mode = "600";
157 text = ''
158 [connection]
159 id=Prixtel
160 uuid=b223f550-dff1-4ba3-9755-cd4557faaa5a
161 type=gsm
162 autoconnect=true
163 permissions=user:julm:;
164
165 [gsm]
166 apn=sl2sfr
167 number=*99#
168 #home-only=true
169
170 [ppp]
171
172 [ipv4]
173 method=auto
174
175 [ipv6]
176 addr-gen-mode=stable-privacy
177 method=auto
178
179 [proxy]
180 '';
181 };
182
183 networking.wireguard.wg-intra.peers = {
184 mermet.enable = true;
185 losurdo.enable = true;
186 oignon.enable = true;
187 patate.enable = true;
188 };
189
190 services.openssh.listenAddresses = [
191 { addr = "${wifiIPv4}.1"; port = 22; }
192 { addr = "${eth1IPv4}.1"; port = 22; }
193 { addr = "${eth2IPv4}.1"; port = 22; }
194 { addr = "${eth3IPv4}.1"; port = 22; }
195 ];
196
197 environment.systemPackages = [
198 pkgs.iw
199 pkgs.modem-manager-gui
200 pkgs.libmbim
201 pkgs.chatty
202 pkgs.calls
203 pkgs.dfeet
204 ];
205
206 # iw dev wlp5s0 station dump
207 # DOC: https://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf
208 services.hostapd = {
209 enable = true;
210 logLevel = 2;
211 interface = wifiIface;
212 # 0 means the AP will search for the channel with the least interferences (ACS)
213 channel = 1;
214 hwMode = "g";
215 ssid = hostName;
216 wpa = false;
217 #wpaPassphrase = "bidonpoissonmaisonronron";
218 countryCode = "FR";
219 extraConfig = ''
220 # WLAN
221 beacon_int=100
222 dtim_period=2 # DTIM (delivery trafic information message)
223 preamble=1
224 # limit the frequencies used to those allowed in the country
225 ieee80211d=1
226
227 # WPA2
228 #wpa_key_mgmt=WPA-PSK
229 #wpa_pairwise=CCMP
230 #rsn_pairwise=CCMP
231 #auth_algs=1 # 0=noauth, 1=wpa, 2=wep, 3=both
232 macaddr_acl=0
233 # QoS support, also required for full speed on 802.11n/ac/ax
234 wmm_enabled=1
235 eap_reauth_period=360000
236 wpa_group_rekey=600
237 wpa_ptk_rekey=600
238 wpa_gmk_rekey=86400
239
240 # N-WLAN
241 ieee80211n=1
242 # See Capabilities in iw list
243 #ht_capab=[HT40+][SHORT-GI-40][DSSS_CCK-40][MAX-AMSDU-3839]
244 require_ht=1
245 obss_interval=0
246
247 # 802.11ac support
248 ieee80211ac=0
249 '';
250 };
251 }