1 { pkgs, lib, config, hostName, ... }:
4 inherit (config) networking;
6 lanIPv4 = "192.168.1.215";
7 lanNet = "192.168.1.0/24";
8 lanIPv4Gateway = "192.168.1.1";
12 networking/nftables.nix
14 networking/wireguard/intranet.nix
15 networking/wireguard/extranet.nix
17 networking/nsupdate.nix
18 networking/wireless.nix
19 networking/openvpn.nix
22 boot.initrd.network = {
24 flushBeforeStage2 = true;
25 # This will automatically load the zfs password prompt on login
26 # and kill the other prompt so boot can continue
27 # The pkill zfs kills the zfs load-key from the console
28 # allowing the boot to continue.
30 echo >>/root/.profile "zfs load-key ${hostName} && pkill zfs"
32 # Retry DHCP forever (because in case of power failure,
33 # the router may take longer to boot).
34 # Beware that this is not interruptible with Ctrl-C
35 udhcpc.extraArgs = [ "--retries=0" ];
38 /* WARNING: using ipconfig (the ip= kernel parameter) IS NOT RELIABLE:
39 a 91.216.110.35/32 becomes a 91.216.110.35/8
40 boot.kernelParams = map
41 (ip: "ip=${ip.clientIP}:${ip.serverIP}:${ip.gatewayIP}:${ip.netmask}:${ip.hostname}:${ip.device}:${ip.autoconf}")
42 [ { clientIP = netIPv4; serverIP = "";
43 gatewayIP = networking.defaultGateway.address;
44 netmask = "255.255.255.255";
45 hostname = ""; device = networking.defaultGateway.interface;
48 { clientIP = lanIPv4; serverIP = "";
50 netmask = "255.255.255.0";
51 hostname = ""; device = "enp2s0";
56 /* DIY network config, but a right one */
58 boot.initrd.preLVMCommands = ''
62 ip link set ${netIface} up
63 ip address add ${lanIPv4}/32 dev ${netIface}
64 ip route add ${lanIPv4Gateway} dev ${netIface}
65 ip route add ${lanNet} dev ${netIface} src ${lanIPv4} proto kernel
66 # NOTE: ${lanIPv4}/24 would not work with initrd's ip, hence ${lanNet}
67 ip route add default via ${lanIPv4Gateway} dev ${netIface}
70 #ip -6 address add ''${lanIPv6} dev ${netIface}
71 #ip -6 route add ''${lanIPv6Gateway} dev ${netIface}
72 #ip -6 route add default via ''${lanIPv6Gateway} dev ${netIface}
82 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
83 #boot.initrd.kernelModules = [ "ipv6" ];
85 # Useless without an out-of-band access, and unsecure
86 # (though / may still be encrypted at this point).
87 # boot.kernelParams = [ "boot.shell_on_fail" ];
90 # Disable IPv6 entirely until it's available
91 boot.kernel.sysctl = {
92 "net.ipv6.conf.${netIface}.disable_ipv6" = 1;
98 domain = "sourcephile.fr";
104 address = lanIPv4Gateway;
105 interface = "${netIface}";
108 address = lanIPv6Gateway;
109 interface = "${netIface}";
115 networking.nftables.ruleset = ''
118 iifname ${netIface} goto input-net
121 oifname ${netIface} jump output-net
122 oifname ${netIface} log level warn prefix "output-net: " counter drop
125 ip daddr ${lanNet} log level info prefix "output-net: lan: " counter accept comment "LAN"
130 oifname ${netIface} masquerade
134 boot.kernel.sysctl."net.ipv6.conf.${netIface}.addr_gen_mode" = 1;
136 security.gnupg.secrets."ipv6/${netIface}/stable_secret" = {};
137 # This is only active in stage2, the initrd will still use the MAC-based SLAAC IPv6.
138 system.activationScripts.ipv6 = ''
139 ${pkgs.procps}/bin/sysctl --quiet net.ipv6.conf.${netIface}.stable_secret="$(cat ${gnupg.secrets."ipv6/${netIface}/stable_secret".path})"
142 networking.interfaces.${netIface} = {
145 ipv4.addresses = [ { address = lanIPv4; prefixLength = 24; } ];
147 ipv4.routes = [ { address = networking.defaultGateway.address; prefixLength = 32; } ];
148 ipv6.addresses = [ { address = lanIPv6; prefixLength = 64; }
149 { address = "fe80::1"; prefixLength = 10; }
151 ipv6.routes = [ { address = networking.defaultGateway6.address; prefixLength = 64; } ];
154 environment.systemPackages = [