nixfiles/presets/nixos/serverHetzner.nix

83 lines
1.5 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;
2024-03-10 17:26:18 +00:00
inherit (pkgs) system;
2023-09-20 15:46:20 +01:00
2023-09-20 18:04:33 +01:00
serverIPs = import "${self}/data/serverIPs.nix";
2023-09-18 03:56:58 +01:00
2024-03-10 17:26:18 +00:00
inherit (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 = [
(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-10-30 13:57:30 +00:00
useDHCP = false;
2023-09-18 03:56:58 +01:00
dhcpcd.enable = false;
2023-10-30 13:57:30 +00:00
useNetworkd = true;
2023-09-18 03:56:58 +01:00
};
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
{
Destination = gateway;
2023-09-18 03:56:58 +01:00
}
{
Gateway = gateway;
GatewayOnLink = true;
2023-09-18 03:56:58 +01:00
}
# v6
{
Gateway = "fe80::1";
2023-09-18 03:56:58 +01:00
}
];
};
};
}