]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/losurdo/networking/wireless.nix
sourcehut: use mkEnableOption
[sourcephile-nix.git] / hosts / losurdo / networking / wireless.nix
1 { pkgs, lib, config, hosts, ... }:
2 let iface = "wlp4s0";
3 in
4 {
5 networking.interfaces.${iface} = {
6 ipv4.addresses = [
7 { address = "192.168.2.1"; prefixLength = 24; }
8 ];
9 };
10 boot.kernel.sysctl."net.ipv6.conf.${iface}.addr_gen_mode" = 1;
11 networking.nftables.ruleset = ''
12 # Hook ${iface} into relevant chains
13 add rule inet filter input iifname "${iface}" jump wifi2fw
14 add rule inet filter input iifname "${iface}" log level warn prefix "wifi2fw: " counter drop
15 add rule inet filter output oifname "${iface}" jump fw2wifi
16 add rule inet filter output oifname "${iface}" log level warn prefix "fw2wifi: " counter drop
17
18 # ${iface} firewalling
19 add rule inet filter fw2wifi counter accept
20 add rule inet filter forward iifname "${iface}" jump fwd-wifi
21
22 # Allow forwarding to the internet
23 add rule inet filter fwd-wifi oifname "enp5s0" counter accept
24
25 # Allow networking services
26 add rule inet filter wifi2fw udp dport 53 counter accept comment "DNS"
27 add rule inet filter wifi2fw tcp dport 53 counter accept comment "DNS"
28 add rule inet filter wifi2fw tcp dport 67 counter accept comment "DHCP"
29 '';
30 #boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
31
32 services.unbound.settings = {
33 server = {
34 interface = [ "192.168.2.1" ];
35 access-control = ["192.168.2.0/24 allow"];
36 local-zone = [
37 "tracking.intl.miui.com always_refuse"
38 "sourcephile.fr typetransparent"
39 ];
40 local-data = [
41 "\"bureau1.sourcephile.fr A 192.168.2.1\""
42 ];
43 };
44 };
45
46 networking.wlanInterfaces = {
47 ${iface} = {
48 device = "phy0";
49 };
50 };
51
52 /*
53 networking.networkmanager.unmanaged = [
54 "interface-name:phy0"
55 "interface-name:${iface}"
56 ];
57 */
58
59 services.hostapd = {
60 enable = true;
61 logLevel = 2;
62 interface = iface;
63 hwMode = "g";
64 ssid = "bureau1";
65 wpa = true;
66 wpaPassphrase = "bidonpoissonmaisonronron";
67 countryCode = "FR";
68 extraConfig = ''
69 '';
70 };
71 services.dhcpd4 = {
72 enable = true;
73 interfaces = [ iface ];
74 extraConfig = ''
75 option subnet-mask 255.255.255.0;
76 option broadcast-address 192.168.2.255;
77 option routers 192.168.2.1;
78 option domain-name-servers 192.168.2.1;
79 subnet 192.168.2.0 netmask 255.255.255.0 {
80 range 192.168.2.100 192.168.2.200;
81 }
82 '';
83 };
84
85 #networking.firewall.allowedUDPPorts = [ 53 67 ]; # DNS & DHCP
86 /*
87 # Sometimes slow connection speeds are attributed to absence of haveged.
88 services.haveged.enable = true;
89 */
90
91 /*
92
93 systemd.services.wifi-relay = let inherit (pkgs) iptables gnugrep;
94 in {
95 description = "iptables rules for wifi-relay";
96 after = [ "dhcpd4.service" ];
97 wantedBy = [ "multi-user.target" ];
98 script = ''
99 ${iptables}/bin/iptables -w -t nat -I POSTROUTING -s 192.168.2.0/24 ! -o wlp4s0 -j MASQUERADE
100 ${iptables}/bin/iptables -w -I FORWARD -i wlp4s0 -s 192.168.2.0/24 -j ACCEPT
101 ${iptables}/bin/iptables -w -I FORWARD -i wlan-station0 -d 192.168.2.0/24 -j ACCEPT
102 '';
103 };
104 */
105 }