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-02-06 11:32:55 +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-02-05 03:45:06 +00:00
|
|
|
mainEthernetInterfaceNames = [ "ens3" "enp0s3" ];
|
|
|
|
internalEthernetInterfaceNames = [ "ens10" "enp0s10" ];
|
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")
|
|
|
|
];
|
|
|
|
|
2023-06-20 11:33:32 +00:00
|
|
|
# Hetzner can only support non-UEFI bootloader (or at least it doesn't with
|
|
|
|
# systemd-boot).
|
|
|
|
boot.loader.grub.enable = lib.mkForce true;
|
2023-01-05 03:08:45 +00:00
|
|
|
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-02-25 02:02:43 +00:00
|
|
|
zramSwap.enable = true;
|
2023-01-06 12:26:32 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2023-02-09 06:17:59 +00:00
|
|
|
# The local DNS resolver. This should be used in conjunction with an
|
|
|
|
# authoritative DNS server as a forwarder. Also, it should live in its
|
|
|
|
# default address at 127.0.0.53 (as of systemd v252).
|
2023-06-20 01:56:40 +00:00
|
|
|
services.resolved = {
|
|
|
|
enable = true;
|
|
|
|
dnssec = "false";
|
|
|
|
};
|
2023-02-06 08:00:56 +00:00
|
|
|
|
2023-01-16 03:44:21 +00:00
|
|
|
# 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-06-22 10:01:19 +00:00
|
|
|
wait-online.ignoredInterfaces = [ "lo" interfaces.lan.ifname ];
|
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-06-22 10:01:19 +00:00
|
|
|
"10-wan" = with interfaces.wan; {
|
2023-01-19 12:12:14 +00:00
|
|
|
matchConfig.Name = lib.concatStringsSep " " mainEthernetInterfaceNames;
|
|
|
|
|
2023-02-05 03:45:06 +00:00
|
|
|
# Setting up IPv6.
|
|
|
|
address = [ "${IPv6.address}/64" ];
|
|
|
|
gateway = [ IPv6.gateway ];
|
2023-01-25 03:38:45 +00:00
|
|
|
|
2023-06-13 05:32:41 +00:00
|
|
|
# Setting up some other networking thingy.
|
|
|
|
domains = [ config.networking.domain ];
|
2023-02-05 03:45:06 +00:00
|
|
|
networkConfig = {
|
2023-02-08 10:30:27 +00:00
|
|
|
# IPv6 has to be manually configured.
|
|
|
|
DHCP = "ipv4";
|
2023-02-22 03:29:43 +00:00
|
|
|
IPForward = true;
|
2023-02-08 10:30:27 +00:00
|
|
|
|
2023-02-06 11:30:51 +00:00
|
|
|
LinkLocalAddressing = "ipv6";
|
2023-02-22 03:29:43 +00:00
|
|
|
IPv6AcceptRA = true;
|
2023-02-08 10:30:27 +00:00
|
|
|
|
2023-02-06 11:30:51 +00:00
|
|
|
DNS = [
|
2023-06-13 05:32:41 +00:00
|
|
|
# The custom DNS servers.
|
|
|
|
IPv4.address
|
|
|
|
IPv6.address
|
|
|
|
|
2023-02-06 11:30:51 +00:00
|
|
|
"2a01:4ff:ff00::add:2"
|
|
|
|
"2a01:4ff:ff00::add:1"
|
|
|
|
];
|
2023-02-05 03:45:06 +00:00
|
|
|
};
|
2023-01-19 12:12:14 +00:00
|
|
|
};
|
|
|
|
|
2023-06-13 05:32:41 +00:00
|
|
|
# The interface for our LAN.
|
2023-06-22 10:01:19 +00:00
|
|
|
"20-lan" = with interfaces.lan; {
|
2023-01-25 03:38:45 +00:00
|
|
|
matchConfig.Name = lib.concatStringsSep " " internalEthernetInterfaceNames;
|
2023-02-05 03:45:06 +00:00
|
|
|
|
2023-06-08 11:53:20 +00:00
|
|
|
# Take note of the private subnets set in your Hetzner Cloud instance
|
|
|
|
# (at least for IPv4 addresses)..
|
2023-01-25 03:38:45 +00:00
|
|
|
address = [
|
2023-02-14 03:00:26 +00:00
|
|
|
"${IPv4.address}/16"
|
|
|
|
"${IPv6.address}/64"
|
2023-01-25 03:38:45 +00:00
|
|
|
];
|
2023-02-05 03:45:06 +00:00
|
|
|
|
2023-02-14 03:00:26 +00:00
|
|
|
# Using the authoritative DNS server to enable accessing them nice
|
|
|
|
# internal services with domain names.
|
2023-06-08 11:51:38 +00:00
|
|
|
dns = [
|
|
|
|
IPv4.address
|
|
|
|
IPv6.address
|
|
|
|
];
|
|
|
|
|
2023-06-08 11:53:20 +00:00
|
|
|
# Force our own internal domain to be used in the system.
|
2023-02-14 03:00:26 +00:00
|
|
|
domains = [ config.networking.fqdn ];
|
|
|
|
|
2023-06-08 11:53:20 +00:00
|
|
|
# Use the gateway to enable resolution of external domains.
|
2023-01-25 03:38:45 +00:00
|
|
|
gateway = [
|
|
|
|
IPv4.gateway
|
|
|
|
IPv6.gateway
|
|
|
|
];
|
2023-02-22 03:29:43 +00:00
|
|
|
|
|
|
|
networkConfig.IPv6AcceptRA = true;
|
2023-01-19 12:12:14 +00:00
|
|
|
};
|
2023-01-14 07:55:30 +00:00
|
|
|
};
|
|
|
|
};
|
2022-11-23 05:27:01 +00:00
|
|
|
}
|