1 { pkgs, config, hostName, ... }:
4 inherit (config) networking;
6 lanNet = "192.168.1.0/24";
10 networking/nftables.nix
12 networking/nsupdate.nix
13 networking/wireless.nix
14 networking/openvpn.nix
17 boot.initrd.network = {
19 flushBeforeStage2 = true;
21 boot.initrd.systemd = {
25 # Start a DHCP Client for IPv4 Addressing/Routing
28 # Accept Router Advertisements for Stateless IPv6 Autoconfiguraton (SLAAC)
30 IPv6PrivacyExtensions = true;
31 KeepConfiguration = "dhcp-on-stop";
37 systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
46 # Start a DHCP Client for IPv4 Addressing/Routing
49 # Accept Router Advertisements for Stateless IPv6 Autoconfiguraton (SLAAC)
51 IPv6PrivacyExtensions = true;
52 KeepConfiguration = "dhcp-on-stop";
55 RequiredForOnline = "no";
61 /* WARNING: using ipconfig (the ip= kernel parameter) IS NOT RELIABLE:
62 a 91.216.110.35/32 becomes a 91.216.110.35/8
63 boot.kernelParams = map
64 (ip: "ip=${ip.clientIP}:${ip.serverIP}:${ip.gatewayIP}:${ip.netmask}:${ip.hostname}:${ip.device}:${ip.autoconf}")
65 [ { clientIP = netIPv4; serverIP = "";
66 gatewayIP = networking.defaultGateway.address;
67 netmask = "255.255.255.255";
68 hostname = ""; device = networking.defaultGateway.interface;
71 { clientIP = lanIPv4; serverIP = "";
73 netmask = "255.255.255.0";
74 hostname = ""; device = "enp2s0";
79 /* DIY network config, but a right one */
81 boot.initrd.preLVMCommands = ''
85 ip link set ${netIface} up
86 ip address add ${lanIPv4}/32 dev ${netIface}
87 ip route add ${lanIPv4Gateway} dev ${netIface}
88 ip route add ${lanNet} dev ${netIface} src ${lanIPv4} proto kernel
89 # NOTE: ${lanIPv4}/24 would not work with initrd's ip, hence ${lanNet}
90 ip route add default via ${lanIPv4Gateway} dev ${netIface}
93 #ip -6 address add ''${lanIPv6} dev ${netIface}
94 #ip -6 route add ''${lanIPv6Gateway} dev ${netIface}
95 #ip -6 route add default via ''${lanIPv6Gateway} dev ${netIface}
105 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
106 #boot.initrd.kernelModules = [ "ipv6" ];
108 # Useless without an out-of-band access, and unsecure
109 # (though / may still be encrypted at this point).
110 # boot.kernelParams = [ "boot.shell_on_fail" ];
113 # Disable IPv6 entirely until it's available
114 boot.kernel.sysctl = {
115 "net.ipv6.conf.${netIface}.disable_ipv6" = 1;
121 domain = "sourcephile.fr";
127 networking.nftables.ruleset = ''
130 iifname ${netIface} goto input-net
133 oifname ${netIface} jump output-net
134 oifname ${netIface} log level warn prefix "output-net: " counter drop
137 ip daddr ${lanNet} log level info prefix "output-net: lan: " counter accept comment "LAN"
142 oifname ${netIface} masquerade
147 security.gnupg.secrets."ipv6/${netIface}/stable_secret" = {};
148 # This is only active in stage2, the initrd will still use the MAC-based SLAAC IPv6.
149 system.activationScripts.ipv6 = ''
150 ${pkgs.procps}/bin/sysctl --quiet net.ipv6.conf.${netIface}.stable_secret="$(cat ${gnupg.secrets."ipv6/${netIface}/stable_secret".path})"
153 environment.systemPackages = [
156 services.vnstat.enable = true;