1 { pkgs, lib, config, hostName, ipv4, hosts, ... }:
4 inherit (config) networking users;
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
19 networking/wireguard.nix
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.extraConfig = lib.mkBefore ''
95 domain = "sourcephile.fr";
99 address = netIPv4Gateway;
100 interface = "${netIface}";
104 address = netIPv6Gateway;
105 interface = "${netIface}";
109 nftables.ruleset = lib.mkAfter ''
112 iifname ${netIface} goto input-net
113 iifname ${lanIface} goto input-lan
116 oifname ${netIface} jump output-net
117 oifname ${netIface} log level warn prefix "output-net: " counter drop
118 oifname ${lanIface} goto output-lan
122 interfaces.${netIface} = {
124 ipv4.addresses = [ { address = netIPv4; prefixLength = 32; } ];
125 ipv4.routes = [ { address = networking.defaultGateway.address; prefixLength = 32; } ];
128 ipv6.addresses = [ { address = netIPv6; prefixLength = 64; }
129 { address = "fe80::1"; prefixLength = 10; }
131 ipv6.routes = [ { address = networking.defaultGateway6.address; prefixLength = 64; } ];
134 interfaces.${lanIface} = {
136 ipv4.addresses = [ { address = lanIPv4; prefixLength = 24; } ];
138 # FIXME: remove this /1 hack when the host will be racked at PTT
139 ipv4.routes = [ { address = "0.0.0.0"; prefixLength = 1; via = "192.168.1.1"; }
140 { address = "128.0.0.0"; prefixLength = 1; via = "192.168.1.1"; }
144 ipv6.addresses = [ { address = "fe80::1"; prefixLength = 10; } ];
148 interfaces.enp3s0 = {