9 inherit (config) networking;
11 lanNet = "192.168.1.0/24";
15 networking/nftables.nix
17 networking/nsupdate.nix
18 networking/wireless.nix
19 networking/openvpn.nix
22 boot.initrd.network = {
24 flushBeforeStage2 = true;
26 boot.initrd.systemd = {
30 # Start a DHCP Client for IPv4 Addressing/Routing
33 # Accept Router Advertisements for Stateless IPv6 Autoconfiguraton (SLAAC)
35 IPv6PrivacyExtensions = true;
36 KeepConfiguration = "dhcp-on-stop";
42 systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
51 # Start a DHCP Client for IPv4 Addressing/Routing
54 # Accept Router Advertisements for Stateless IPv6 Autoconfiguraton (SLAAC)
56 IPv6PrivacyExtensions = true;
57 KeepConfiguration = "dhcp-on-stop";
60 RequiredForOnline = "no";
67 WARNING: using ipconfig (the ip= kernel parameter) IS NOT RELIABLE:
68 a 91.216.110.35/32 becomes a 91.216.110.35/8
69 boot.kernelParams = map
70 (ip: "ip=${ip.clientIP}:${ip.serverIP}:${ip.gatewayIP}:${ip.netmask}:${ip.hostname}:${ip.device}:${ip.autoconf}")
71 [ { clientIP = netIPv4; serverIP = "";
72 gatewayIP = networking.defaultGateway.address;
73 netmask = "255.255.255.255";
74 hostname = ""; device = networking.defaultGateway.interface;
77 { clientIP = lanIPv4; serverIP = "";
79 netmask = "255.255.255.0";
80 hostname = ""; device = "enp2s0";
85 # DIY network config, but a right one
87 boot.initrd.preLVMCommands = ''
91 ip link set ${netIface} up
92 ip address add ${lanIPv4}/32 dev ${netIface}
93 ip route add ${lanIPv4Gateway} dev ${netIface}
94 ip route add ${lanNet} dev ${netIface} src ${lanIPv4} proto kernel
95 # NOTE: ${lanIPv4}/24 would not work with initrd's ip, hence ${lanNet}
96 ip route add default via ${lanIPv4Gateway} dev ${netIface}
99 #ip -6 address add ''${lanIPv6} dev ${netIface}
100 #ip -6 route add ''${lanIPv6Gateway} dev ${netIface}
101 #ip -6 route add default via ''${lanIPv6Gateway} dev ${netIface}
111 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
112 #boot.initrd.kernelModules = [ "ipv6" ];
114 # Useless without an out-of-band access, and unsecure
115 # (though / may still be encrypted at this point).
116 # boot.kernelParams = [ "boot.shell_on_fail" ];
119 # Disable IPv6 entirely until it's available
120 boot.kernel.sysctl = {
121 "net.ipv6.conf.${netIface}.disable_ipv6" = 1;
127 domain = "sourcephile.fr";
133 networking.nftables.ruleset = ''
136 iifname ${netIface} goto input-net
139 oifname ${netIface} jump output-net
140 oifname ${netIface} log level warn prefix "output-net: " counter drop
143 ip daddr ${lanNet} log level info prefix "output-net: lan: " counter accept comment "LAN"
148 oifname ${netIface} masquerade
153 security.gnupg.secrets."ipv6/${netIface}/stable_secret" = {};
154 # This is only active in stage2, the initrd will still use the MAC-based SLAAC IPv6.
155 system.activationScripts.ipv6 = ''
156 ${pkgs.procps}/bin/sysctl --quiet net.ipv6.conf.${netIface}.stable_secret="$(cat ${gnupg.secrets."ipv6/${netIface}/stable_secret".path})"
159 environment.systemPackages = [
162 services.vnstat.enable = true;
163 systemd.services.vnstat.serviceConfig = {
164 Restart = "on-failure";