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/nsupdate.nix
15 networking/wireless.nix
16 networking/openvpn.nix
19 boot.initrd.network = {
21 flushBeforeStage2 = true;
22 # This will automatically load the zfs password prompt on login
23 # and kill the other prompt so boot can continue
24 # The pkill zfs kills the zfs load-key from the console
25 # allowing the boot to continue.
27 echo >>/root/.profile "zfs load-key ${hostName} && pkill zfs"
29 # Retry DHCP forever (because in case of power failure,
30 # the router may take longer to boot).
31 # Beware that this is not interruptible with Ctrl-C
32 udhcpc.extraArgs = [ "--retries=0" ];
35 /* WARNING: using ipconfig (the ip= kernel parameter) IS NOT RELIABLE:
36 a 91.216.110.35/32 becomes a 91.216.110.35/8
37 boot.kernelParams = map
38 (ip: "ip=${ip.clientIP}:${ip.serverIP}:${ip.gatewayIP}:${ip.netmask}:${ip.hostname}:${ip.device}:${ip.autoconf}")
39 [ { clientIP = netIPv4; serverIP = "";
40 gatewayIP = networking.defaultGateway.address;
41 netmask = "255.255.255.255";
42 hostname = ""; device = networking.defaultGateway.interface;
45 { clientIP = lanIPv4; serverIP = "";
47 netmask = "255.255.255.0";
48 hostname = ""; device = "enp2s0";
53 /* DIY network config, but a right one */
55 boot.initrd.preLVMCommands = ''
59 ip link set ${netIface} up
60 ip address add ${lanIPv4}/32 dev ${netIface}
61 ip route add ${lanIPv4Gateway} dev ${netIface}
62 ip route add ${lanNet} dev ${netIface} src ${lanIPv4} proto kernel
63 # NOTE: ${lanIPv4}/24 would not work with initrd's ip, hence ${lanNet}
64 ip route add default via ${lanIPv4Gateway} dev ${netIface}
67 #ip -6 address add ''${lanIPv6} dev ${netIface}
68 #ip -6 route add ''${lanIPv6Gateway} dev ${netIface}
69 #ip -6 route add default via ''${lanIPv6Gateway} dev ${netIface}
79 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
80 #boot.initrd.kernelModules = [ "ipv6" ];
82 # Useless without an out-of-band access, and unsecure
83 # (though / may still be encrypted at this point).
84 # boot.kernelParams = [ "boot.shell_on_fail" ];
87 # Disable IPv6 entirely until it's available
88 boot.kernel.sysctl = {
89 "net.ipv6.conf.${netIface}.disable_ipv6" = 1;
95 domain = "sourcephile.fr";
101 address = lanIPv4Gateway;
102 interface = "${netIface}";
105 address = lanIPv6Gateway;
106 interface = "${netIface}";
112 networking.nftables.ruleset = ''
115 iifname ${netIface} goto input-net
118 oifname ${netIface} jump output-net
119 oifname ${netIface} log level warn prefix "output-net: " counter drop
122 ip daddr ${lanNet} log level info prefix "output-net: lan: " counter accept comment "LAN"
127 oifname ${netIface} masquerade
131 boot.kernel.sysctl."net.ipv6.conf.${netIface}.addr_gen_mode" = 1;
133 security.gnupg.secrets."ipv6/${netIface}/stable_secret" = {};
134 # This is only active in stage2, the initrd will still use the MAC-based SLAAC IPv6.
135 system.activationScripts.ipv6 = ''
136 ${pkgs.procps}/bin/sysctl --quiet net.ipv6.conf.${netIface}.stable_secret="$(cat ${gnupg.secrets."ipv6/${netIface}/stable_secret".path})"
139 networking.interfaces.${netIface} = {
142 ipv4.addresses = [ { address = lanIPv4; prefixLength = 24; } ];
144 ipv4.routes = [ { address = networking.defaultGateway.address; prefixLength = 32; } ];
145 ipv6.addresses = [ { address = lanIPv6; prefixLength = 64; }
146 { address = "fe80::1"; prefixLength = 10; }
148 ipv6.routes = [ { address = networking.defaultGateway6.address; prefixLength = 64; } ];
151 environment.systemPackages = [