]> Git — Sourcephile - sourcephile-nix.git/blob - servers/mermet/lesptts.nix
nix: rename {dovecot => dovecot2}
[sourcephile-nix.git] / servers / mermet / lesptts.nix
1 { pkgs, lib, config, nodes, ... }:
2 with builtins;
3 let
4 inherit (config) networking;
5 netIPv4 = "91.216.110.35";
6 netIPv4Gateway = "91.216.110.1";
7 netIPv6 = "2001:912:400:104::35";
8 netIPv6Gateway = "2001:912:400:104::1";
9 lanIPv4 = "192.168.1.214";
10 lanNet = "192.168.1.0/24";
11 lanIPv4Gateway = "192.168.1.1";
12 in
13 {
14 /* WARNING: using ipconfig (the ip= kernel parameter) IS NOT RELIABLE:
15 a 91.216.110.35/32 becomes a 91.216.110.35/8
16 boot.kernelParams = map
17 (ip: "ip=${ip.clientIP}:${ip.serverIP}:${ip.gatewayIP}:${ip.netmask}:${ip.hostname}:${ip.device}:${ip.autoconf}")
18 [ { clientIP = netIPv4; serverIP = "";
19 gatewayIP = networking.defaultGateway.address;
20 netmask = "255.255.255.255";
21 hostname = ""; device = networking.defaultGateway.interface;
22 autoconf = "off";
23 }
24 { clientIP = lanIPv4; serverIP = "";
25 gatewayIP = "";
26 netmask = "255.255.255.0";
27 hostname = ""; device = "enp2s0";
28 autoconf = "off";
29 }
30 ];
31 */
32 /* DIY network config, but a right one */
33 boot.initrd.preLVMCommands = ''
34 set -x
35
36 # IPv4 net
37 ip link set enp1s0 up
38 ip address add ${netIPv4}/32 dev enp1s0
39 ip route add ${netIPv4Gateway} dev enp1s0
40 ip route add default via ${netIPv4Gateway} dev enp1s0
41
42 # IPv4 lan
43 ip link set enp2s0 up
44 ip address add ${lanIPv4}/32 dev enp2s0
45 ip route add ${lanIPv4Gateway} dev enp2s0
46 ip route add ${lanNet} dev enp2s0 src ${lanIPv4} proto kernel
47 # NOTE: ${lanIPv4}/24 would not work with initrd's ip, hence ${lanNet}
48
49 # IPv6 net
50 ip -6 address add ${netIPv6} dev enp1s0
51 ip -6 route add ${netIPv6Gateway} dev enp1s0
52 ip -6 route add default via ${netIPv6Gateway} dev enp1s0
53
54 ip -4 address
55 ip -4 route
56 ip -6 address
57 ip -6 route
58
59 set +x
60
61 # Since boot.initrd.network's preLVMCommands won't set hasNetwork=1
62 # we have to run the postCommands ourselves.
63 ${config.boot.initrd.network.postCommands}
64 '';
65 # Workaround https://github.com/NixOS/nixpkgs/issues/56822
66 boot.initrd.kernelModules = [ "ipv6" ];
67
68 networking = {
69 useDHCP = false;
70 defaultGateway = {
71 address = netIPv4Gateway;
72 interface = "enp1s0";
73 };
74 defaultGateway6 = {
75 address = netIPv6Gateway;
76 interface = "enp1s0";
77 };
78 #nameservers = [ ];
79 interfaces.enp1s0 = {
80 useDHCP = false;
81 ipv4.addresses = [ { address = netIPv4; prefixLength = 32; } ];
82 ipv4.routes = [ { address = networking.defaultGateway.address; prefixLength = 32; } ];
83
84 ipv6.addresses = [ { address = netIPv6; prefixLength = 64; }
85 { address = "fe80::1"; prefixLength = 10; }
86 ];
87 ipv6.routes = [ { address = networking.defaultGateway6.address; prefixLength = 64; } ];
88 };
89 interfaces.enp2s0 = {
90 useDHCP = false;
91 ipv4.addresses = [ { address = lanIPv4; prefixLength = 24; } ];
92 # FIXME: remove this /1 hack when the machine will be racked at PTT
93 ipv4.routes = [ { address = "0.0.0.0"; prefixLength = 1; via = "192.168.1.1"; }
94 { address = "128.0.0.0"; prefixLength = 1; via = "192.168.1.1"; }
95 ];
96 ipv6.addresses = [ { address = "fe80::1"; prefixLength = 10; } ];
97 ipv6.routes = [ ];
98 };
99 interfaces.enp3s0 = {
100 useDHCP = false;
101 };
102 };
103 deployment = /*lib.mkIf (builtins.hasAttr "mermet" nodes)*/ {
104 targetHost = (elemAt networking.interfaces.enp2s0.ipv4.addresses 0).address;
105 };
106 }