1 { lib, config, hostName, ... }:
4 inherit (config) networking;
6 netIPv4 = "80.67.180.129";
7 netIPv4Gateway = "80.67.180.134";
8 #netIPv6 = "2001:912:400:104::35";
9 #netIPv6Gateway = "2001:912:400:104::1";
11 lanIPv4 = "192.168.1.214";
12 lanNet = "192.168.1.0/24";
13 lanIPv4Gateway = "192.168.1.1";
17 networking/nftables.nix
20 _module.args.ipv4 = netIPv4;
22 /* WARNING: using ipconfig (the ip= kernel parameter) IS NOT RELIABLE:
23 a 91.216.110.35/32 becomes a 91.216.110.35/8
24 boot.kernelParams = map
25 (ip: "ip=${ip.clientIP}:${ip.serverIP}:${ip.gatewayIP}:${ip.netmask}:${ip.hostname}:${ip.device}:${ip.autoconf}")
26 [ { clientIP = netIPv4; serverIP = "";
27 gatewayIP = networking.defaultGateway.address;
28 netmask = "255.255.255.255";
29 hostname = ""; device = networking.defaultGateway.interface;
32 { clientIP = lanIPv4; serverIP = "";
34 netmask = "255.255.255.0";
35 hostname = ""; device = "${lanIface}";
40 /* DIY network config, but a right one */
41 boot.initrd.preLVMCommands = ''
45 ip link set ${netIface} up
46 ip address add ${netIPv4}/32 dev ${netIface}
47 ip route add ${netIPv4Gateway} dev ${netIface}
48 ip route add default via ${netIPv4Gateway} dev ${netIface}
51 ip link set ${lanIface} up
52 ip address add ${lanIPv4}/32 dev ${lanIface}
53 ip route add ${lanIPv4Gateway} dev ${lanIface}
54 ip route add ${lanNet} dev ${lanIface} src ${lanIPv4} proto kernel
55 # NOTE: ${lanIPv4}/24 would not work with initrd's ip, hence ${lanNet}
58 #ip -6 address add ''${netIPv6} dev ${netIface}
59 #ip -6 route add ''${netIPv6Gateway} dev ${netIface}
60 #ip -6 route add default via ''${netIPv6Gateway} dev ${netIface}
69 # Since boot.initrd.network's preLVMCommands won't set hasNetwork=1
70 # we have to run the postCommands ourselves.
71 ${config.boot.initrd.network.postCommands}
74 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
75 # TODO: the issue is now closed
76 #boot.initrd.kernelModules = [ "ipv6" ];
78 # Useless without an out-of-band access, and unsecure
79 # (though / may still be encrypted at this point).
80 # boot.kernelParams = [ "boot.shell_on_fail" ];
82 # Disable IPv6 entirely until it's available
83 boot.kernel.sysctl = {
84 "net.ipv6.conf.${netIface}.disable_ipv6" = 1;
87 services.knot.settingsFreeform.server.listen = [
93 domain = "sourcephile.fr";
97 address = netIPv4Gateway;
98 interface = "${netIface}";
102 address = netIPv6Gateway;
103 interface = "${netIface}";
107 nftables.ruleset = lib.mkAfter ''
110 iifname ${netIface} goto input-net
111 iifname ${lanIface} goto input-lan
114 oifname ${netIface} jump output-net
115 oifname ${netIface} log level warn prefix "output-net: " counter drop
116 oifname ${lanIface} goto output-lan
120 interfaces.${netIface} = {
122 ipv4.addresses = [{ address = netIPv4; prefixLength = 32; }];
123 ipv4.routes = [{ address = networking.defaultGateway.address; prefixLength = 32; }];
126 ipv6.addresses = [ { address = netIPv6; prefixLength = 64; }
127 { address = "fe80::1"; prefixLength = 10; }
129 ipv6.routes = [ { address = networking.defaultGateway6.address; prefixLength = 64; } ];
132 interfaces.${lanIface} = {
134 ipv4.addresses = [{ address = lanIPv4; prefixLength = 24; }];
136 # FIXME: remove this /1 hack when the host will be racked at PTT
137 ipv4.routes = [ { address = "0.0.0.0"; prefixLength = 1; via = "192.168.1.1"; }
138 { address = "128.0.0.0"; prefixLength = 1; via = "192.168.1.1"; }
142 ipv6.addresses = [ { address = "fe80::1"; prefixLength = 10; } ];
146 interfaces.enp3s0 = {
151 services.vnstat.enable = true;