1 { pkgs, lib, config, machineName, machines, wireguard, ... }:
4 #lanIPv4 = "192.168.1.215";
5 lanNet = "192.168.1.0/24";
6 #lanIPv4Gateway = "192.168.1.1";
10 networking/nftables.nix
12 networking/wireguard.nix
15 boot.initrd.network = {
17 flushBeforeStage2 = true;
18 # This will automatically load the zfs password prompt on login
19 # and kill the other prompt so boot can continue
20 # The pkill zfs kills the zfs load-key from the console
21 # allowing the boot to continue.
23 echo >>/root/.profile "zfs load-key ${machineName} && pkill zfs"
27 /* WARNING: using ipconfig (the ip= kernel parameter) IS NOT RELIABLE:
28 a 91.216.110.35/32 becomes a 91.216.110.35/8
29 boot.kernelParams = map
30 (ip: "ip=${ip.clientIP}:${ip.serverIP}:${ip.gatewayIP}:${ip.netmask}:${ip.hostname}:${ip.device}:${ip.autoconf}")
31 [ { clientIP = netIPv4; serverIP = "";
32 gatewayIP = networking.defaultGateway.address;
33 netmask = "255.255.255.255";
34 hostname = ""; device = networking.defaultGateway.interface;
37 { clientIP = lanIPv4; serverIP = "";
39 netmask = "255.255.255.0";
40 hostname = ""; device = "enp2s0";
45 /* DIY network config, but a right one */
47 boot.initrd.preLVMCommands = ''
52 ip address add ${lanIPv4}/32 dev enp5s0
53 ip route add ${lanIPv4Gateway} dev enp5s0
54 ip route add ${lanNet} dev enp5s0 src ${lanIPv4} proto kernel
55 # NOTE: ${lanIPv4}/24 would not work with initrd's ip, hence ${lanNet}
56 ip route add default via ${lanIPv4Gateway} dev enp5s0
59 #ip -6 address add ''${lanIPv6} dev enp5s0
60 #ip -6 route add ''${lanIPv6Gateway} dev enp5s0
61 #ip -6 route add default via ''${lanIPv6Gateway} dev enp5s0
70 # Since boot.initrd.network's preLVMCommands won't set hasNetwork=1
71 # we have to run the postCommands ourselves.
72 ${config.boot.initrd.network.postCommands}
75 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
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" ];
83 # Disable IPv6 entirely until it's available
84 boot.kernel.sysctl = {
85 "net.ipv6.conf.enp5s0.disable_ipv6" = 1;
90 hostName = machineName;
91 domain = "sourcephile.fr";
96 address = lanIPv4Gateway;
100 address = lanIPv6Gateway;
101 interface = "enp5s0";
107 networking.nftables.ruleset = ''
108 add rule inet filter input iifname "enp5s0" goto net2fw
109 add rule inet filter output oifname "enp5s0" jump fw2net
110 add rule inet filter output oifname "enp5s0" log level warn prefix "fw2net: " counter drop
111 add rule inet filter fw2net ip daddr ${lanNet} counter accept comment "LAN"
113 networking.interfaces.enp5s0 = {
115 #ipv4.addresses = [ { address = lanIPv4; prefixLength = 24; } ];
116 #ipv4.routes = [ { address = networking.defaultGateway.address; prefixLength = 32; } ];
119 ipv6.addresses = [ { address = lanIPv6; prefixLength = 64; }
120 { address = "fe80::1"; prefixLength = 10; }
122 ipv6.routes = [ { address = networking.defaultGateway6.address; prefixLength = 64; } ];
125 networking.interfaces.wlp4s0 = {