nixfiles/presets/nixos/serverHetzner.nix

86 lines
1.6 KiB
Nix
Raw Normal View History

2023-09-18 03:56:58 +01:00
{
self,
config,
modulesPath,
2023-09-20 15:46:20 +01:00
pkgs,
2023-09-18 03:56:58 +01:00
lib,
...
}: let
2023-09-20 15:46:20 +01:00
inherit (lib.lists) optionals;
2023-09-18 03:56:58 +01:00
inherit (lib.modules) mkForce;
2023-09-20 15:46:20 +01:00
system = pkgs.system;
2023-09-20 18:04:33 +01:00
serverIPs = import "${self}/data/serverIPs.nix";
2023-09-18 03:56:58 +01:00
hostName = config.networking.hostName;
2023-09-20 18:04:33 +01:00
hostServerIPs = serverIPs.${hostName};
2023-09-20 15:46:20 +01:00
gateway = "172.31.1.1";
netmask = "255.255.255.255";
2023-09-18 03:56:58 +01:00
in {
imports = [
2023-09-20 16:37:10 +01:00
(modulesPath + "/installer/scan/not-detected.nix")
2023-09-18 03:56:58 +01:00
(modulesPath + "/profiles/qemu-guest.nix")
];
systemd.services = {
systemd-networkd-wait-online.enable = mkForce false;
};
networking = {
2023-09-20 17:45:45 +01:00
usePredictableInterfaceNames = true;
2023-09-18 03:56:58 +01:00
dhcpcd.enable = false;
};
2023-09-20 16:18:44 +01:00
boot.initrd.kernelModules = [
"virtio_gpu"
"virtio_pci"
"virtio_net"
"virtio_scsi"
];
2023-09-20 15:46:20 +01:00
boot.kernelParams =
[
2023-09-20 18:04:33 +01:00
"ip=${hostServerIPs.ipv4}::${gateway}:${netmask}:${hostName}:enp1s0:any"
2023-09-20 16:18:44 +01:00
"boot.shell_on_fail"
"nohibernate"
"loglevel=4"
2023-09-20 15:46:20 +01:00
]
2023-09-20 23:34:25 +01:00
++ (lib.optionals (system == "aarch64-linux") ["console=tty"]);
2023-09-20 15:46:20 +01:00
2023-09-18 03:56:58 +01:00
systemd.network = {
enable = true;
2023-09-20 16:18:44 +01:00
networks."enp1s0" = {
name = "enp1s0";
2023-09-18 03:56:58 +01:00
networkConfig.DHCP = "no";
address = [
# v4
2023-09-20 18:04:33 +01:00
"${hostServerIPs.ipv4}/32"
2023-09-18 03:56:58 +01:00
# v6
2023-09-20 18:04:33 +01:00
"${hostServerIPs.ipv6}/64"
2023-09-18 03:56:58 +01:00
];
routes = [
# v4
{
routeConfig = {
2023-09-20 18:04:33 +01:00
Destination = gateway;
2023-09-18 03:56:58 +01:00
};
}
{
routeConfig = {
2023-09-20 18:04:33 +01:00
Gateway = gateway;
2023-09-18 03:56:58 +01:00
GatewayOnLink = true;
};
}
# v6
{
routeConfig.Gateway = "fe80::1";
}
];
};
};
}