2023-05-27 16:57:28 +01:00
|
|
|
{ lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib.my) net;
|
2023-11-02 13:41:50 +00:00
|
|
|
inherit (lib.my.c.colony) domain prefixes;
|
2023-05-27 16:57:28 +01:00
|
|
|
in
|
|
|
|
{
|
2022-05-28 23:05:30 +01:00
|
|
|
imports = [ ./vms ];
|
|
|
|
|
2022-02-20 15:59:07 +00:00
|
|
|
nixos.systems.colony = {
|
|
|
|
system = "x86_64-linux";
|
2022-05-28 18:38:03 +01:00
|
|
|
nixpkgs = "mine-stable";
|
|
|
|
home-manager = "mine-stable";
|
2022-02-19 22:55:53 +00:00
|
|
|
|
2022-05-28 15:30:12 +01:00
|
|
|
assignments = {
|
2022-11-21 01:21:50 +00:00
|
|
|
routing = {
|
|
|
|
name = "colony-routing";
|
2023-05-27 16:57:28 +01:00
|
|
|
inherit domain;
|
|
|
|
ipv4.address = net.cidr.host 2 prefixes.base.v4;
|
2022-11-21 01:21:50 +00:00
|
|
|
};
|
2022-05-28 15:30:12 +01:00
|
|
|
internal = {
|
|
|
|
altNames = [ "vm" ];
|
2023-05-27 16:57:28 +01:00
|
|
|
inherit domain;
|
2022-11-21 01:21:50 +00:00
|
|
|
ipv4 = {
|
2023-05-27 16:57:28 +01:00
|
|
|
address = net.cidr.host 0 prefixes.vip1;
|
2022-11-21 01:21:50 +00:00
|
|
|
mask = 32;
|
|
|
|
gateway = null;
|
|
|
|
genPTR = false;
|
|
|
|
};
|
2022-05-31 21:58:29 +01:00
|
|
|
ipv6 = {
|
2022-05-29 03:30:40 +01:00
|
|
|
iid = "::2";
|
2023-05-27 16:57:28 +01:00
|
|
|
address = net.cidr.host 2 prefixes.base.v6;
|
2022-05-29 03:30:40 +01:00
|
|
|
};
|
2022-05-28 15:30:12 +01:00
|
|
|
};
|
|
|
|
vms = {
|
2022-06-10 20:42:13 +01:00
|
|
|
name = "colony-vms";
|
2023-05-27 16:57:28 +01:00
|
|
|
inherit domain;
|
2022-05-28 15:30:12 +01:00
|
|
|
ipv4 = {
|
2023-05-27 16:57:28 +01:00
|
|
|
address = net.cidr.host 1 prefixes.vms.v4;
|
2022-05-28 15:30:12 +01:00
|
|
|
gateway = null;
|
|
|
|
};
|
2023-05-27 16:57:28 +01:00
|
|
|
ipv6.address = net.cidr.host 1 prefixes.vms.v6;
|
2022-05-28 15:30:12 +01:00
|
|
|
};
|
2022-05-17 23:27:14 +01:00
|
|
|
};
|
|
|
|
|
2022-05-28 15:30:12 +01:00
|
|
|
configuration = { lib, pkgs, modulesPath, config, systems, assignments, allAssignments, ... }:
|
2022-02-21 00:37:09 +00:00
|
|
|
let
|
2022-05-29 15:22:49 +01:00
|
|
|
inherit (lib) mkIf mkMerge mkForce;
|
2022-05-17 23:27:14 +01:00
|
|
|
inherit (lib.my) networkdAssignment;
|
2022-02-21 00:37:09 +00:00
|
|
|
in
|
2022-02-20 15:59:07 +00:00
|
|
|
{
|
2022-06-17 22:26:51 +01:00
|
|
|
hardware = {
|
|
|
|
enableRedistributableFirmware = true;
|
|
|
|
cpu = {
|
|
|
|
amd.updateMicrocode = true;
|
|
|
|
};
|
2023-11-11 14:09:45 +00:00
|
|
|
rasdaemon.enable = true;
|
2022-06-17 22:26:51 +01:00
|
|
|
};
|
|
|
|
|
2022-06-17 00:54:28 +01:00
|
|
|
boot = {
|
2023-06-24 16:33:16 +01:00
|
|
|
kernelPackages = pkgs.linuxKernel.packages.linux_6_1.extend (self: super: {
|
2022-06-18 01:27:40 +01:00
|
|
|
kernel = super.kernel.override {
|
|
|
|
structuredExtraConfig = with lib.kernel; {
|
|
|
|
#SOME_OPT = yes;
|
|
|
|
#A_MOD = module;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2022-06-17 00:54:28 +01:00
|
|
|
kernelModules = [ "kvm-amd" ];
|
2022-06-18 01:27:40 +01:00
|
|
|
kernelParams = [ "amd_iommu=on" "console=ttyS0,115200n8" "console=ttyS1,115200n8" "console=tty0" ];
|
2022-06-17 00:54:28 +01:00
|
|
|
initrd = {
|
2023-02-19 16:47:13 +00:00
|
|
|
kernelModules = [ "dm-raid" ];
|
2022-06-17 00:54:28 +01:00
|
|
|
availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" "sr_mod" ];
|
|
|
|
};
|
|
|
|
};
|
2022-06-17 22:26:51 +01:00
|
|
|
|
2022-02-20 15:59:07 +00:00
|
|
|
fileSystems = {
|
|
|
|
"/boot" = {
|
2022-06-17 00:54:28 +01:00
|
|
|
device = "/dev/disk/by-uuid/C1C9-9CBC";
|
2022-02-20 15:59:07 +00:00
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
"/nix" = {
|
2023-02-19 16:47:13 +00:00
|
|
|
device = "/dev/main/colony-nix";
|
2022-02-20 15:59:07 +00:00
|
|
|
fsType = "ext4";
|
|
|
|
};
|
|
|
|
"/persist" = {
|
2023-02-19 16:47:13 +00:00
|
|
|
device = "/dev/main/colony-persist";
|
2022-02-20 15:59:07 +00:00
|
|
|
fsType = "ext4";
|
|
|
|
neededForBoot = true;
|
|
|
|
};
|
2023-02-20 01:43:48 +00:00
|
|
|
"/mnt/backup" = {
|
2023-02-22 01:26:19 +00:00
|
|
|
device = "/dev/main/backup";
|
2023-02-20 01:43:48 +00:00
|
|
|
fsType = "ext4";
|
|
|
|
};
|
2022-02-20 15:59:07 +00:00
|
|
|
};
|
2022-06-17 22:26:51 +01:00
|
|
|
|
2023-10-31 17:11:20 +00:00
|
|
|
programs.ssh.knownHostsFiles = [
|
2023-11-02 13:41:50 +00:00
|
|
|
lib.my.c.sshKeyFiles.rsyncNet
|
2023-10-31 17:11:20 +00:00
|
|
|
];
|
|
|
|
|
2022-05-16 00:05:02 +01:00
|
|
|
services = {
|
2023-11-02 13:41:50 +00:00
|
|
|
fstrim = lib.my.c.colony.fstrimConfig;
|
2022-05-16 00:05:02 +01:00
|
|
|
lvm = {
|
|
|
|
boot.thin.enable = true;
|
|
|
|
dmeventd.enable = true;
|
|
|
|
};
|
2022-06-19 14:07:27 +01:00
|
|
|
|
|
|
|
netdata = {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
# Ignore the VCCM sensor (RAM voltage is 1.35V with XMP enabled)
|
|
|
|
"plugin:freeipmi"."command options" = "ignore 5";
|
|
|
|
};
|
|
|
|
};
|
2022-06-18 01:27:40 +01:00
|
|
|
|
|
|
|
smartd = {
|
|
|
|
enable = true;
|
|
|
|
autodetect = true;
|
2022-06-18 03:38:04 +01:00
|
|
|
extraOptions = [ "-A /var/log/smartd/" "--interval=600" ];
|
2022-06-18 01:27:40 +01:00
|
|
|
};
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
pciutils
|
2022-06-18 01:27:40 +01:00
|
|
|
usbutils
|
2022-06-06 15:53:57 +01:00
|
|
|
partclone
|
2022-06-17 00:54:28 +01:00
|
|
|
lm_sensors
|
2022-06-18 01:27:40 +01:00
|
|
|
linuxPackages.cpupower
|
|
|
|
smartmontools
|
2022-08-01 17:44:08 +01:00
|
|
|
xfsprogs
|
2022-05-16 00:05:02 +01:00
|
|
|
];
|
2022-02-20 15:59:07 +00:00
|
|
|
|
2022-05-16 00:05:02 +01:00
|
|
|
systemd = {
|
2023-10-31 17:11:20 +00:00
|
|
|
tmpfiles.rules = [
|
|
|
|
"d /var/log/smartd 0755 root root"
|
|
|
|
];
|
|
|
|
|
2022-06-18 01:27:40 +01:00
|
|
|
services = {
|
|
|
|
"serial-getty@ttyS0".enable = true;
|
|
|
|
"serial-getty@ttyS1".enable = true;
|
|
|
|
|
2023-11-12 18:30:06 +00:00
|
|
|
rsync-lvm-meta = {
|
|
|
|
description = "rsync lvm metadata backups / archives to rsync.net";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
|
|
|
|
# Only run when no other process is using CPU or disk
|
|
|
|
CPUSchedulingPolicy = "idle";
|
|
|
|
IOSchedulingClass = "idle";
|
|
|
|
};
|
|
|
|
script = ''
|
|
|
|
${pkgs.rsync}/bin/rsync -av --delete --delete-after \
|
|
|
|
-e "${pkgs.openssh}/bin/ssh -i ${config.age.secrets."colony/rsync.key".path}" \
|
|
|
|
/etc/lvm/{archive,backup} zh2855@zh2855.rsync.net:colony/lvm/
|
|
|
|
'';
|
|
|
|
wantedBy = [ "borgthin-job-main.service" ];
|
|
|
|
after = [ "borgthin-job-main.service" ];
|
|
|
|
};
|
2023-10-31 17:11:20 +00:00
|
|
|
borgthin-rsync = {
|
|
|
|
description = "rsync borgthin backups to rsync.net";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
|
|
|
|
# Only run when no other process is using CPU or disk
|
|
|
|
CPUSchedulingPolicy = "idle";
|
|
|
|
IOSchedulingClass = "idle";
|
|
|
|
};
|
|
|
|
script = ''
|
|
|
|
${pkgs.rsync}/bin/rsync -av --delete --delete-after \
|
|
|
|
-e "${pkgs.openssh}/bin/ssh -i ${config.age.secrets."colony/rsync.key".path}" \
|
|
|
|
/mnt/backup/main/ zh2855@zh2855.rsync.net:borg/colony/
|
|
|
|
'';
|
|
|
|
wantedBy = [ "borgthin-job-main.service" ];
|
|
|
|
after = [ "borgthin-job-main.service" ];
|
|
|
|
};
|
|
|
|
};
|
2022-06-18 03:38:04 +01:00
|
|
|
|
2022-05-16 00:05:02 +01:00
|
|
|
network = {
|
2022-05-18 23:29:52 +01:00
|
|
|
links = {
|
2022-06-17 00:54:28 +01:00
|
|
|
"10-wan0" = {
|
|
|
|
matchConfig.MACAddress = "d0:50:99:fa:a7:99";
|
|
|
|
linkConfig.Name = "wan0";
|
|
|
|
};
|
|
|
|
"10-wan1" = {
|
|
|
|
matchConfig.MACAddress = "d0:50:99:fa:a7:9a";
|
|
|
|
linkConfig.Name = "wan1";
|
2022-05-18 23:29:52 +01:00
|
|
|
};
|
|
|
|
};
|
2022-05-28 15:30:12 +01:00
|
|
|
netdevs = {
|
|
|
|
"25-base".netdevConfig = {
|
|
|
|
Name = "base";
|
|
|
|
Kind = "bridge";
|
|
|
|
};
|
2022-06-30 03:24:10 +01:00
|
|
|
"30-base-dummy".netdevConfig = {
|
|
|
|
Name = "base0";
|
|
|
|
Kind = "dummy";
|
|
|
|
};
|
2022-05-29 15:22:49 +01:00
|
|
|
|
2022-05-28 15:30:12 +01:00
|
|
|
"25-vms".netdevConfig = {
|
|
|
|
Name = "vms";
|
|
|
|
Kind = "bridge";
|
|
|
|
};
|
2022-05-29 15:22:49 +01:00
|
|
|
"30-vms-dummy".netdevConfig = {
|
|
|
|
Name = "vms0";
|
|
|
|
Kind = "dummy";
|
|
|
|
};
|
2022-05-02 17:34:48 +01:00
|
|
|
};
|
2022-05-28 15:30:12 +01:00
|
|
|
|
2022-05-18 22:52:42 +01:00
|
|
|
networks = {
|
2022-11-21 01:21:50 +00:00
|
|
|
"80-base" = mkMerge [
|
|
|
|
(networkdAssignment "base" assignments.routing)
|
|
|
|
(networkdAssignment "base" assignments.internal)
|
|
|
|
];
|
2022-06-30 03:24:10 +01:00
|
|
|
"80-base-dummy" = {
|
|
|
|
matchConfig.Name = "base0";
|
|
|
|
networkConfig.Bridge = "base";
|
|
|
|
};
|
2022-05-18 23:29:52 +01:00
|
|
|
"80-base-ext" = {
|
|
|
|
matchConfig.Name = "base-ext";
|
|
|
|
networkConfig.Bridge = "base";
|
|
|
|
};
|
2022-05-28 15:30:12 +01:00
|
|
|
|
|
|
|
"80-vms" = mkMerge [
|
2022-05-29 03:30:40 +01:00
|
|
|
(networkdAssignment "vms" assignments.vms)
|
2022-05-28 15:30:12 +01:00
|
|
|
{
|
|
|
|
networkConfig = {
|
|
|
|
IPv6AcceptRA = mkForce false;
|
|
|
|
IPv6SendRA = true;
|
|
|
|
};
|
|
|
|
ipv6SendRAConfig = {
|
2022-05-29 15:48:26 +01:00
|
|
|
DNS = [ allAssignments.estuary.base.ipv6.address ];
|
2022-05-28 15:30:12 +01:00
|
|
|
Domains = [ config.networking.domain ];
|
|
|
|
};
|
|
|
|
ipv6Prefixes = [
|
|
|
|
{
|
2023-11-02 13:41:50 +00:00
|
|
|
ipv6PrefixConfig.Prefix = prefixes.vms.v6;
|
2022-05-29 03:30:40 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
routes = map (r: { routeConfig = r; }) [
|
|
|
|
{
|
2023-11-02 13:41:50 +00:00
|
|
|
Destination = prefixes.ctrs.v4;
|
2022-11-21 01:21:50 +00:00
|
|
|
Gateway = allAssignments.shill.routing.ipv4.address;
|
2022-05-29 03:30:40 +01:00
|
|
|
}
|
|
|
|
{
|
2023-11-02 13:41:50 +00:00
|
|
|
Destination = prefixes.ctrs.v6;
|
2022-11-21 01:21:50 +00:00
|
|
|
Gateway = allAssignments.shill.internal.ipv6.address;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Destination = allAssignments.shill.internal.ipv4.address;
|
|
|
|
Gateway = allAssignments.shill.routing.ipv4.address;
|
2022-05-28 15:30:12 +01:00
|
|
|
}
|
2022-08-01 17:44:08 +01:00
|
|
|
|
|
|
|
{
|
2023-11-02 13:41:50 +00:00
|
|
|
Destination = prefixes.oci.v4;
|
2022-11-21 01:21:50 +00:00
|
|
|
Gateway = allAssignments.whale2.routing.ipv4.address;
|
2022-08-01 17:44:08 +01:00
|
|
|
}
|
|
|
|
{
|
2023-11-02 13:41:50 +00:00
|
|
|
Destination = prefixes.oci.v6;
|
2022-11-21 01:21:50 +00:00
|
|
|
Gateway = allAssignments.whale2.internal.ipv6.address;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
Destination = allAssignments.whale2.internal.ipv4.address;
|
|
|
|
Gateway = allAssignments.whale2.routing.ipv4.address;
|
2022-08-01 17:44:08 +01:00
|
|
|
}
|
2022-05-28 15:30:12 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2022-05-29 15:22:49 +01:00
|
|
|
# Just so the vms interface will come up (in networkd's eyes), allowing dependant VMs to start.
|
|
|
|
# Could tweak the `waitOnline` for a single VM, but this seems better overall?
|
|
|
|
"80-vms-dummy" = {
|
|
|
|
matchConfig.Name = "vms0";
|
|
|
|
networkConfig.Bridge = "vms";
|
2022-05-18 22:52:42 +01:00
|
|
|
};
|
2023-08-26 23:26:19 +01:00
|
|
|
|
|
|
|
"90-vm-mail" = {
|
|
|
|
matchConfig.Name = "vm-mail";
|
|
|
|
address = [
|
|
|
|
(net.cidr.subnet 8 1 prefixes.cust.v4)
|
|
|
|
prefixes.mail.v6
|
|
|
|
];
|
|
|
|
networkConfig = {
|
|
|
|
IPv6AcceptRA = false;
|
|
|
|
IPv6SendRA = true;
|
|
|
|
};
|
|
|
|
ipv6Prefixes = [
|
|
|
|
{
|
|
|
|
ipv6PrefixConfig.Prefix = prefixes.mail.v6;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
routes = map (r: { routeConfig = r; }) [
|
|
|
|
{
|
|
|
|
Destination = prefixes.mail.v4;
|
|
|
|
Scope = "link";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-11-11 15:56:27 +00:00
|
|
|
|
|
|
|
"90-vm-darts" = {
|
|
|
|
matchConfig.Name = "vm-darts";
|
|
|
|
address = [
|
|
|
|
(net.cidr.subnet 8 2 prefixes.cust.v4)
|
|
|
|
prefixes.darts.v6
|
|
|
|
];
|
|
|
|
networkConfig = {
|
|
|
|
IPv6AcceptRA = false;
|
|
|
|
IPv6SendRA = true;
|
|
|
|
};
|
|
|
|
ipv6Prefixes = [
|
|
|
|
{
|
|
|
|
ipv6PrefixConfig.Prefix = prefixes.darts.v6;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
routes = map (r: { routeConfig = r; }) [
|
|
|
|
{
|
|
|
|
Destination = prefixes.darts.v4;
|
|
|
|
Scope = "link";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2022-05-18 22:52:42 +01:00
|
|
|
};
|
2022-05-02 17:34:48 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-16 00:05:02 +01:00
|
|
|
#environment.etc."udev/udev.conf".text = "udev_log=debug";
|
2022-03-26 14:20:30 +00:00
|
|
|
#systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
|
2022-05-02 20:40:11 +01:00
|
|
|
virtualisation = {
|
|
|
|
cores = 8;
|
|
|
|
memorySize = 8192;
|
2022-05-16 00:05:02 +01:00
|
|
|
qemu.options = [
|
|
|
|
"-machine q35"
|
|
|
|
"-accel kvm,kernel-irqchip=split"
|
|
|
|
"-device intel-iommu,intremap=on,caching-mode=on"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
my = {
|
|
|
|
#deploy.generate.system.mode = "boot";
|
|
|
|
secrets = {
|
2022-06-17 00:54:28 +01:00
|
|
|
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPIijqzAWF6OxKr4aeCa1TAc5xGn4rdIjVTt0wAPU6uY";
|
2023-02-20 01:43:48 +00:00
|
|
|
files = {
|
|
|
|
"colony/borg-pass.txt" = {};
|
2023-10-31 17:11:20 +00:00
|
|
|
"colony/rsync.key" = {};
|
2023-02-20 01:43:48 +00:00
|
|
|
};
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
server.enable = true;
|
|
|
|
|
|
|
|
firewall = {
|
2022-06-12 17:33:33 +01:00
|
|
|
trustedInterfaces = [ "vms" ];
|
|
|
|
extraRules = ''
|
2023-11-11 15:56:27 +00:00
|
|
|
define cust = { vm-mail, vm-darts }
|
2022-06-12 17:33:33 +01:00
|
|
|
table inet filter {
|
|
|
|
chain forward {
|
|
|
|
# Trust that the outer firewall has done the filtering!
|
2023-08-26 23:26:19 +01:00
|
|
|
iifname base oifname { vms, $cust } accept
|
|
|
|
iifname $cust accept # trust for now...
|
2022-06-12 17:33:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
2022-05-16 00:05:02 +01:00
|
|
|
};
|
2023-02-20 01:43:48 +00:00
|
|
|
|
|
|
|
borgthin = {
|
|
|
|
enable = true;
|
|
|
|
jobs = {
|
|
|
|
main = {
|
|
|
|
repo = "/mnt/backup/main";
|
|
|
|
passFile = config.age.secrets."colony/borg-pass.txt".path;
|
|
|
|
lvs = map (lv: "main/${lv}") [
|
|
|
|
"colony-persist"
|
|
|
|
"vm-shill-persist"
|
|
|
|
"minio"
|
|
|
|
"oci"
|
|
|
|
"vm-estuary-persist"
|
|
|
|
"vm-whale2-persist"
|
2023-08-26 23:26:19 +01:00
|
|
|
"vm-mail-data"
|
2023-02-20 01:43:48 +00:00
|
|
|
];
|
|
|
|
compression = "zstd,5";
|
|
|
|
extraCreateArgs = [ "--stats" ];
|
|
|
|
prune.keep = {
|
|
|
|
last = 1;
|
|
|
|
within = "1d";
|
|
|
|
daily = 7;
|
|
|
|
weekly = 4;
|
|
|
|
monthly = 12;
|
|
|
|
yearly = -1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-05-02 20:40:11 +01:00
|
|
|
};
|
2022-02-20 15:59:07 +00:00
|
|
|
};
|
2022-02-19 22:55:53 +00:00
|
|
|
};
|
2022-02-13 13:10:21 +00:00
|
|
|
}
|