]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/losurdo/networking.nix
nix: update julm-nix input
[sourcephile-nix.git] / hosts / losurdo / networking.nix
1 { pkgs, lib, config, hostName, ... }:
2 with builtins;
3 let
4 inherit (config) networking;
5 netIface = "enp5s0";
6 lanIPv4 = "192.168.1.215";
7 lanNet = "192.168.1.0/24";
8 lanIPv4Gateway = "192.168.1.1";
9 in
10 {
11 imports = [
12 networking/nftables.nix
13 #networking/tor.nix
14 networking/nsupdate.nix
15 networking/wireless.nix
16 networking/openvpn.nix
17 ];
18
19 boot.initrd.network = {
20 enable = true;
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.
26 postCommands = ''
27 echo >>/root/.profile "zfs load-key ${hostName} && pkill zfs"
28 '';
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" ];
33 };
34
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;
43 autoconf = "off";
44 }
45 { clientIP = lanIPv4; serverIP = "";
46 gatewayIP = "";
47 netmask = "255.255.255.0";
48 hostname = ""; device = "enp2s0";
49 autoconf = "off";
50 }
51 ];
52 */
53 /* DIY network config, but a right one */
54 /*
55 boot.initrd.preLVMCommands = ''
56 set -x
57
58 # IPv4 lan
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}
65
66 # IPv6 net
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}
70
71 ip -4 address
72 ip -4 route
73 #ip -6 address
74 #ip -6 route
75
76 set +x
77 '';
78 */
79 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
80 #boot.initrd.kernelModules = [ "ipv6" ];
81
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" ];
85
86 /*
87 # Disable IPv6 entirely until it's available
88 boot.kernel.sysctl = {
89 "net.ipv6.conf.${netIface}.disable_ipv6" = 1;
90 };
91 */
92
93 networking = {
94 hostName = hostName;
95 domain = "sourcephile.fr";
96
97 useDHCP = false;
98 enableIPv6 = true;
99 /*
100 defaultGateway = {
101 address = lanIPv4Gateway;
102 interface = "${netIface}";
103 };
104 defaultGateway6 = {
105 address = lanIPv6Gateway;
106 interface = "${netIface}";
107 };
108 */
109 #nameservers = [ ];
110 };
111
112 networking.nftables.ruleset = ''
113 table inet filter {
114 chain input {
115 iifname ${netIface} goto input-net
116 }
117 chain output {
118 oifname ${netIface} jump output-net
119 oifname ${netIface} log level warn prefix "output-net: " counter drop
120 }
121 chain output-net {
122 ip daddr ${lanNet} log level info prefix "output-net: lan: " counter accept comment "LAN"
123 }
124 }
125 table inet nat {
126 chain postrouting {
127 oifname ${netIface} masquerade
128 }
129 }
130 '';
131 boot.kernel.sysctl."net.ipv6.conf.${netIface}.addr_gen_mode" = 1;
132 /*
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})"
137 '';
138 */
139 networking.interfaces.${netIface} = {
140 useDHCP = true;
141 /*
142 ipv4.addresses = [ { address = lanIPv4; prefixLength = 24; } ];
143
144 ipv4.routes = [ { address = networking.defaultGateway.address; prefixLength = 32; } ];
145 ipv6.addresses = [ { address = lanIPv6; prefixLength = 64; }
146 { address = "fe80::1"; prefixLength = 10; }
147 ];
148 ipv6.routes = [ { address = networking.defaultGateway6.address; prefixLength = 64; } ];
149 */
150 };
151 environment.systemPackages = [
152 pkgs.iodine
153 ];
154 }