2023-01-06 12:26:32 +00:00
|
|
|
{ config, lib, pkgs, modulesPath, ... }:
|
2022-11-23 05:27:01 +00:00
|
|
|
|
2022-11-25 13:27:23 +00:00
|
|
|
# Most of the filesystems listed here are supposed to be overriden to default
|
|
|
|
# settings of whatever image format configuration this host system will import
|
|
|
|
# from nixos-generators.
|
2023-01-16 03:44:21 +00:00
|
|
|
let
|
2023-01-19 12:16:01 +00:00
|
|
|
inherit (builtins) toString;
|
2023-01-25 03:38:45 +00:00
|
|
|
inherit (import ./networks.nix) interfaces;
|
2023-01-16 03:44:21 +00:00
|
|
|
|
2023-01-19 12:12:14 +00:00
|
|
|
# This is just referring to the same interface just with alternative names.
|
2023-01-25 03:38:45 +00:00
|
|
|
mainEthernetInterfaceNames = [ "ens10" "enp0s10" ];
|
|
|
|
internalEthernetInterfaceNames = [ "ens11" "enp0s11" ];
|
2023-01-19 12:12:14 +00:00
|
|
|
in
|
2022-11-23 05:27:01 +00:00
|
|
|
{
|
2023-01-05 03:08:45 +00:00
|
|
|
imports = [
|
|
|
|
(modulesPath + "/profiles/qemu-guest.nix")
|
|
|
|
];
|
|
|
|
|
|
|
|
boot.loader.grub.device = "/dev/sda";
|
2023-01-06 12:26:32 +00:00
|
|
|
boot.initrd.availableKernelModules = [ "ata_piix" "virtio_pci" "virtio_scsi" "xhci_pci" "sd_mod" "sr_mod" ];
|
2023-01-05 03:08:45 +00:00
|
|
|
boot.initrd.kernelModules = [ "nvme" ];
|
|
|
|
|
2023-01-28 16:01:32 +00:00
|
|
|
fileSystems."/" = {
|
2022-11-23 05:27:01 +00:00
|
|
|
label = "nixos";
|
|
|
|
fsType = "ext4";
|
2023-01-05 02:56:35 +00:00
|
|
|
options = [ "defaults" ];
|
2022-11-23 05:27:01 +00:00
|
|
|
};
|
2023-01-05 02:56:35 +00:00
|
|
|
|
2023-01-28 16:01:32 +00:00
|
|
|
fileSystems."/boot" = {
|
2023-01-05 02:56:35 +00:00
|
|
|
label = "boot";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
2023-01-06 12:26:32 +00:00
|
|
|
zramSwap = {
|
|
|
|
enable = true;
|
|
|
|
numDevices = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
|
|
|
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
|
|
|
|
2023-01-14 07:55:30 +00:00
|
|
|
networking = {
|
2023-01-21 01:02:11 +00:00
|
|
|
enableIPv6 = true;
|
2023-01-18 07:42:33 +00:00
|
|
|
usePredictableInterfaceNames = true;
|
2023-01-16 03:44:21 +00:00
|
|
|
useNetworkd = true;
|
|
|
|
|
|
|
|
# We're using networkd to configure so we're disabling this
|
|
|
|
# service.
|
2023-01-21 01:02:11 +00:00
|
|
|
useDHCP = false;
|
2023-01-16 03:44:21 +00:00
|
|
|
dhcpcd.enable = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
# The interface configuration is based from the following discussion:
|
|
|
|
# https://discourse.nixos.org/t/nixos-on-hetzner-cloud-servers-ipv6/221/
|
|
|
|
systemd.network = {
|
|
|
|
enable = true;
|
2023-01-19 12:12:14 +00:00
|
|
|
|
|
|
|
# For more information, you can look at Hetzner documentation from
|
|
|
|
# https://docs.hetzner.com/robot/dedicated-server/ip/additional-ip-adresses/
|
|
|
|
networks = {
|
2023-01-25 03:38:45 +00:00
|
|
|
"20-wan" = {
|
2023-01-19 12:12:14 +00:00
|
|
|
matchConfig.Name = lib.concatStringsSep " " mainEthernetInterfaceNames;
|
|
|
|
|
|
|
|
# Setting the primary static IPs.
|
2023-01-23 09:46:32 +00:00
|
|
|
address = with interfaces; [
|
|
|
|
# The public IPs.
|
2023-01-25 03:38:45 +00:00
|
|
|
"${main'.IPv4.address}/32"
|
|
|
|
"${main'.IPv6.address}/128"
|
2023-01-19 12:12:14 +00:00
|
|
|
];
|
|
|
|
|
2023-01-25 03:38:45 +00:00
|
|
|
networkConfig.IPForward = true;
|
|
|
|
|
|
|
|
gateway = [
|
|
|
|
interfaces.main'.IPv4.gateway
|
|
|
|
interfaces.main'.IPv6.gateway
|
|
|
|
];
|
2023-01-19 12:12:14 +00:00
|
|
|
|
|
|
|
routes = [
|
2023-01-25 03:38:45 +00:00
|
|
|
{ routeConfig.Gateway = interfaces.main'.IPv6.gateway; }
|
|
|
|
{ routeConfig.Destination = interfaces.main'.IPv4.address; }
|
2023-01-19 12:12:14 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
routeConfig = {
|
2023-01-25 03:38:45 +00:00
|
|
|
Gateway = interfaces.main'.IPv4.gateway;
|
2023-01-19 12:12:14 +00:00
|
|
|
GatewayOnLink = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-01-25 03:38:45 +00:00
|
|
|
"20-lan" = with interfaces.internal; {
|
|
|
|
matchConfig.Name = lib.concatStringsSep " " internalEthernetInterfaceNames;
|
|
|
|
address = [
|
|
|
|
"${IPv4.address}/16"
|
|
|
|
"${IPv6.address}/64"
|
|
|
|
];
|
|
|
|
gateway = [
|
|
|
|
IPv4.gateway
|
|
|
|
IPv6.gateway
|
|
|
|
];
|
|
|
|
|
|
|
|
routes = [
|
|
|
|
{ routeConfig.Gateway = IPv6.gateway; }
|
|
|
|
{ routeConfig.Destination = IPv4.address; }
|
|
|
|
|
|
|
|
{
|
|
|
|
routeConfig = {
|
|
|
|
Gateway = IPv4.gateway;
|
|
|
|
GatewayOnLink = true;
|
|
|
|
};
|
|
|
|
}
|
2023-01-23 09:46:32 +00:00
|
|
|
];
|
2023-01-21 10:57:37 +00:00
|
|
|
};
|
|
|
|
|
2023-01-25 03:38:45 +00:00
|
|
|
"60-internal" = {
|
|
|
|
matchConfig.Name = "ens*";
|
2023-01-19 12:12:14 +00:00
|
|
|
networkConfig.DHCP = "yes";
|
|
|
|
};
|
2023-01-14 07:55:30 +00:00
|
|
|
};
|
|
|
|
};
|
2023-01-16 03:44:21 +00:00
|
|
|
|
|
|
|
# This is to look out for any errors that will occur for my networking setup
|
|
|
|
# which is always a possibility.
|
2023-01-25 03:38:45 +00:00
|
|
|
systemd.services.systemd-networkd.serviceConfig.Environment = "SYSTEMD_LOG_LEVEL=info";
|
2022-11-23 05:27:01 +00:00
|
|
|
}
|