nixfiles/nixos/boxes/colony/vms/shill/default.nix

195 lines
5.8 KiB
Nix
Raw Normal View History

{ lib, ... }:
let
inherit (lib.my) net;
2023-11-02 13:41:50 +00:00
inherit (lib.my.c.colony) domain prefixes;
in
{
imports = [ ./containers ];
nixos.systems.shill = {
system = "x86_64-linux";
nixpkgs = "mine";
assignments = {
2022-11-21 01:21:50 +00:00
routing = {
name = "shill-vm-routing";
inherit domain;
ipv4.address = net.cidr.host 2 prefixes.vms.v4;
2022-11-21 01:21:50 +00:00
};
internal = {
name = "shill-vm";
altNames = [ "ctr" ];
inherit domain;
2022-11-21 01:21:50 +00:00
ipv4 = {
address = net.cidr.host 1 prefixes.vip1;
2022-11-21 01:21:50 +00:00
mask = 32;
gateway = null;
genPTR = false;
};
ipv6 = {
iid = "::2";
address = net.cidr.host 2 prefixes.vms.v6;
};
};
ctrs = {
name = "shill-vm-ctrs";
inherit domain;
ipv4 = {
address = net.cidr.host 1 prefixes.ctrs.v4;
gateway = null;
};
ipv6.address = net.cidr.host 1 prefixes.ctrs.v6;
};
};
configuration = { lib, pkgs, modulesPath, config, assignments, allAssignments, ... }:
let
2022-05-31 21:25:51 +01:00
inherit (builtins) mapAttrs;
2022-06-11 19:13:20 +01:00
inherit (lib) mkIf mkMerge mkForce;
inherit (lib.my) networkdAssignment;
in
{
2023-11-13 08:14:16 +00:00
imports = [ "${modulesPath}/profiles/qemu-guest.nix" ./hercules.nix ./gitea.nix ];
config = mkMerge [
{
2022-06-12 02:40:57 +01:00
boot = {
kernelParams = [ "console=ttyS0,115200n8" ];
# Stolen from nixos/modules/services/torrent/transmission.nix
kernel.sysctl = {
2022-11-20 04:44:22 +00:00
"net.core.rmem_max" = 4194304; # 4MB
"net.core.wmem_max" = 1048576; # 1MB
2022-06-12 02:40:57 +01:00
"net.ipv4.ip_local_port_range" = "16384 65535";
#"net.netfilter.nf_conntrack_generic_timeout" = 60;
#"net.netfilter.nf_conntrack_tcp_timeout_established" = 600;
#"net.netfilter.nf_conntrack_tcp_timeout_time_wait" = 1;
2022-06-12 02:40:57 +01:00
"net.netfilter.nf_conntrack_max" = 1048576;
};
};
fileSystems = {
"/boot" = {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
};
"/nix" = {
2022-06-06 15:53:57 +01:00
device = "/dev/disk/by-label/nix";
fsType = "ext4";
};
"/persist" = {
2022-06-06 15:53:57 +01:00
device = "/dev/disk/by-label/persist";
fsType = "ext4";
neededForBoot = true;
};
2023-02-21 14:22:10 +00:00
"/mnt/media" = {
device = "/dev/disk/by-label/media";
fsType = "ext4";
};
2022-07-16 15:01:15 +01:00
"/mnt/minio" = {
device = "/dev/disk/by-label/minio";
fsType = "xfs";
};
};
2022-07-16 21:33:07 +01:00
nix.settings = {
# Exclude S3 cache that we're right next to
substituters = mkForce [ "https://cache.nixos.org" ];
};
2022-06-12 17:27:11 +01:00
services = {
2023-11-02 13:41:50 +00:00
fstrim = lib.my.c.colony.fstrimConfig;
2022-06-12 17:27:11 +01:00
netdata.enable = true;
};
systemd.network = {
links = {
"10-vms" = {
2022-06-18 02:56:05 +01:00
matchConfig.MACAddress = "52:54:00:27:3d:5c";
linkConfig.Name = "vms";
};
};
netdevs."25-ctrs".netdevConfig = {
Name = "ctrs";
Kind = "bridge";
};
networks = {
2022-11-21 01:21:50 +00:00
"80-vms" = mkMerge [
(networkdAssignment "vms" assignments.routing)
(networkdAssignment "vms" assignments.internal)
];
"80-ctrs" = mkMerge [
(networkdAssignment "ctrs" assignments.ctrs)
{
networkConfig = {
IPv6AcceptRA = mkForce false;
IPv6SendRA = true;
};
ipv6SendRAConfig = {
DNS = [ allAssignments.estuary.base.ipv6.address ];
Domains = [ config.networking.domain ];
};
ipv6Prefixes = [
{
2023-11-02 13:41:50 +00:00
ipv6PrefixConfig.Prefix = prefixes.ctrs.v6;
}
];
}
];
};
};
my = {
2022-06-18 02:56:05 +01:00
secrets.key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ6bc1pQCYalLXdB4X+7kFXtkTdFalbH5rchjuYj2ceU";
server.enable = true;
firewall = {
2022-06-12 17:27:11 +01:00
tcp.allowed = [ 19999 ];
2022-06-12 17:33:33 +01:00
trustedInterfaces = [ "ctrs" ];
extraRules = ''
table inet filter {
chain forward {
# Trust that the outer firewall has done the filtering!
iifname vms oifname ctrs accept
}
}
'';
};
2022-06-11 19:13:20 +01:00
containers.instances =
let
instances = {
middleman = {
bindMounts = {
"/mnt/media" = {};
};
};
2022-06-11 19:13:20 +01:00
vaultwarden = {};
colony-psql = {};
chatterbox = {};
jackflix = {
bindMounts = {
"/mnt/media".readOnly = false;
};
};
2022-07-16 15:01:15 +01:00
object = {
bindMounts = {
"/mnt/minio".readOnly = false;
};
};
2022-11-20 02:43:48 +00:00
toot = {};
2022-06-11 19:13:20 +01:00
};
in
mkMerge [
instances
(mapAttrs (n: i: {
networking.bridge = "ctrs";
}) instances)
];
};
}
];
};
};
}