2023-01-17 22:09:48 +00:00
|
|
|
# SPDX-FileCopyrightText: 2023 Luke Granger-Brown <depot@lukegb.com>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
{ depot, lib, pkgs, config, ... }:
|
2023-03-12 03:15:34 +00:00
|
|
|
let
|
|
|
|
vhostsConfig = {
|
|
|
|
int = rec {
|
|
|
|
proxy = _apply (value: { extraConfig = ''
|
|
|
|
${bind}
|
|
|
|
reverse_proxy ${value}
|
|
|
|
''; }) {
|
|
|
|
"http://deluge.int.lukegb.com" = "http://localhost:8112";
|
|
|
|
"http://radarr.int.lukegb.com" = "http://localhost:7878";
|
|
|
|
"http://sonarr.int.lukegb.com" = "http://localhost:8989";
|
|
|
|
};
|
|
|
|
serve = _apply (value: { extraConfig = ''
|
|
|
|
${bind}
|
|
|
|
root * ${value}
|
|
|
|
file_server
|
|
|
|
''; }) {
|
|
|
|
"http://int.lukegb.com" = depot.web.int;
|
|
|
|
"http://logged-out.int.lukegb.com" = depot.web.logged-out-int;
|
|
|
|
};
|
|
|
|
other = _apply lib.id {
|
|
|
|
"http://content.int.lukegb.com" = {
|
|
|
|
serverAliases = ["http://content.int.lukegb.com:18081"];
|
|
|
|
extraConfig = ''
|
|
|
|
${bind}
|
|
|
|
root * /store/content
|
|
|
|
file_server browse
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
_apply = f: builtins.mapAttrs (name: value: lib.recursiveUpdate hostBase (f value));
|
|
|
|
};
|
|
|
|
};
|
2023-10-13 20:44:20 +00:00
|
|
|
vhosts = vhostsConfig.int.proxy // vhostsConfig.int.serve // vhostsConfig.int.other // {
|
|
|
|
"https://plex.lukegb.xyz" = {
|
|
|
|
extraConfig = ''
|
|
|
|
tls /var/lib/acme/plex.lukegb.xyz/fullchain.pem /var/lib/acme/plex.lukegb.xyz/privkey.pem
|
|
|
|
redir https://plex.lukegb.xyz:32400{uri}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
"http://plex.lukegb.xyz" = {
|
|
|
|
extraConfig = ''
|
|
|
|
redir https://plex.lukegb.xyz:32400{uri}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-03-12 03:15:34 +00:00
|
|
|
hostBase = {
|
|
|
|
extraConfig = ''
|
|
|
|
${bind}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
bind = "bind [${config.my.ip.tailscale6}] ${config.my.ip.tailscale}";
|
|
|
|
in
|
2023-01-17 22:09:48 +00:00
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
../lib/zfs.nix
|
2023-01-18 23:41:42 +00:00
|
|
|
../lib/bgp.nix
|
2023-03-12 03:51:10 +00:00
|
|
|
../lib/whitby-distributed.nix
|
2023-03-09 21:33:42 +00:00
|
|
|
../lib/nixbuild-distributed.nix
|
2023-03-11 18:15:45 +00:00
|
|
|
../lib/gitlab-runner-cacher.nix
|
2023-03-12 03:15:34 +00:00
|
|
|
../lib/coredns/default.nix
|
|
|
|
../lib/deluge.nix
|
|
|
|
../lib/plex.nix
|
2024-03-24 23:25:15 +00:00
|
|
|
./vm-bridge.nix
|
2024-03-25 19:12:55 +00:00
|
|
|
#./vxlan-bridge.nix
|
2023-01-17 22:09:48 +00:00
|
|
|
];
|
|
|
|
|
2023-10-13 20:44:20 +00:00
|
|
|
my.plex.customTLS = {
|
|
|
|
enable = true;
|
|
|
|
domain = "plex.lukegb.xyz";
|
|
|
|
};
|
|
|
|
users.users.caddy.extraGroups = lib.mkAfter [ "plexcert" ];
|
|
|
|
|
2023-01-18 21:43:48 +00:00
|
|
|
# Otherwise _this_ machine won't enumerate things properly.
|
|
|
|
boot.zfs.devNodes = "/dev/disk/by-id";
|
|
|
|
|
2023-01-17 22:09:48 +00:00
|
|
|
boot.initrd = {
|
|
|
|
availableKernelModules = [
|
2023-01-18 21:43:48 +00:00
|
|
|
"nvme"
|
|
|
|
"xhci_pci"
|
2023-01-17 22:09:48 +00:00
|
|
|
"ahci"
|
|
|
|
"usb_storage"
|
2023-01-18 21:43:48 +00:00
|
|
|
"usbhid"
|
2023-01-17 22:09:48 +00:00
|
|
|
"sd_mod"
|
|
|
|
"sr_mod"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
boot.kernelModules = [ "kvm-amd" ];
|
2023-01-18 21:43:48 +00:00
|
|
|
hardware.cpu.amd.updateMicrocode = true;
|
2023-01-17 22:09:48 +00:00
|
|
|
|
|
|
|
# Use the systemd-boot EFI boot loader.
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
|
2023-01-18 21:43:48 +00:00
|
|
|
boot.blacklistedKernelModules = [ "ib_core" "irdma" ];
|
|
|
|
|
2023-01-17 22:09:48 +00:00
|
|
|
powerManagement.cpuFreqGovernor = lib.mkDefault "performance";
|
|
|
|
services.zfs.rollbackOnBoot = {
|
|
|
|
enable = true;
|
2023-01-18 21:43:48 +00:00
|
|
|
snapshot = "zfast/local/root@blank";
|
2023-01-17 22:09:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
fileSystems = let
|
|
|
|
zfs = device: {
|
|
|
|
device = device;
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
|
|
|
in {
|
2023-01-18 21:43:48 +00:00
|
|
|
"/" = zfs "zfast/local/root";
|
|
|
|
"/nix" = zfs "zfast/local/nix";
|
|
|
|
"/tmp" = zfs "zfast/local/tmp";
|
2023-01-17 22:09:48 +00:00
|
|
|
|
2023-01-18 21:43:48 +00:00
|
|
|
"/persist" = zfs "zfast/safe/persist";
|
2023-03-12 03:15:34 +00:00
|
|
|
"/store" = zfs "zslow/safe/store";
|
2023-01-18 21:43:48 +00:00
|
|
|
"/home" = (zfs "zslow/safe/home") // { neededForBoot = true; };
|
2023-01-17 22:09:48 +00:00
|
|
|
|
|
|
|
"/boot" = {
|
2023-01-18 21:43:48 +00:00
|
|
|
device = "/dev/disk/by-label/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
"/boot2" = {
|
|
|
|
device = "/dev/disk/by-label/ESP2";
|
2023-01-17 22:09:48 +00:00
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
};
|
2023-01-18 21:43:48 +00:00
|
|
|
boot.loader.systemd-boot.extraInstallCommands = ''
|
|
|
|
rsync -a /boot/ /boot2/
|
|
|
|
'';
|
2023-01-17 22:09:48 +00:00
|
|
|
|
|
|
|
nix.settings.max-jobs = lib.mkDefault 8;
|
|
|
|
|
|
|
|
# Networking!
|
|
|
|
networking = {
|
|
|
|
hostName = "cofractal-ams01";
|
|
|
|
domain = "as205479.net";
|
|
|
|
hostId = "a1cf1a9f";
|
|
|
|
useNetworkd = true;
|
|
|
|
|
|
|
|
nameservers = [
|
|
|
|
"2001:4860:4860::8888"
|
|
|
|
"2001:4860:4860::8844"
|
|
|
|
"8.8.8.8"
|
|
|
|
"8.8.4.4"
|
|
|
|
];
|
2023-01-18 21:43:48 +00:00
|
|
|
bonds.bond0 = {
|
2024-03-21 22:21:47 +00:00
|
|
|
interfaces = [ "enp45s0f0np0" "enp45s0f1np1" ];
|
2023-01-18 21:43:48 +00:00
|
|
|
driverOptions = {
|
|
|
|
miimon = "100";
|
|
|
|
mode = "802.3ad";
|
|
|
|
};
|
2023-01-17 22:09:48 +00:00
|
|
|
};
|
2023-10-24 22:51:25 +00:00
|
|
|
defaultGateway6 = {
|
|
|
|
address = "2a09:a446:1337:ffff::1";
|
|
|
|
interface = "bond0";
|
|
|
|
};
|
2023-01-18 21:43:48 +00:00
|
|
|
interfaces.bond0 = {
|
|
|
|
ipv6.addresses = [
|
|
|
|
{ address = "2a09:a446:1337::10"; prefixLength = 64; }
|
|
|
|
{ address = "2a09:a446:1337:ffff::10"; prefixLength = 120; }
|
|
|
|
];
|
|
|
|
ipv4.addresses = [
|
|
|
|
{ address = "199.19.152.160"; prefixLength = 30; }
|
|
|
|
];
|
2023-01-17 22:09:48 +00:00
|
|
|
};
|
2023-03-12 20:33:25 +00:00
|
|
|
firewall.interfaces.bond0.allowedTCPPorts = [
|
|
|
|
32400 # Plex
|
2023-10-13 20:44:20 +00:00
|
|
|
4001 # IPFS
|
|
|
|
80 # HTTP
|
|
|
|
443 # HTTPS
|
2023-03-12 20:33:25 +00:00
|
|
|
];
|
|
|
|
firewall.interfaces.bond0.allowedUDPPorts = [
|
|
|
|
34197 # factorio
|
2023-10-13 20:44:20 +00:00
|
|
|
4001 # IPFS
|
|
|
|
443 # HTTP/3
|
2023-03-12 20:33:25 +00:00
|
|
|
];
|
2023-01-17 22:09:48 +00:00
|
|
|
};
|
2023-05-11 10:52:47 +00:00
|
|
|
systemd.network.networks."40-bond0".linkConfig.RequiredForOnline = "yes";
|
2024-03-21 22:21:47 +00:00
|
|
|
systemd.network.networks."40-enp45s0f0np0".linkConfig.RequiredForOnline = "no";
|
|
|
|
systemd.network.networks."40-enp45s0f1np1".linkConfig.RequiredForOnline = "no";
|
2023-05-11 10:52:47 +00:00
|
|
|
systemd.network.networks."50-tailscale".linkConfig.RequiredForOnline = "no";
|
2023-05-25 23:01:17 +00:00
|
|
|
my.ip.tailscale = "100.83.36.130";
|
|
|
|
my.ip.tailscale6 = "fd7a:115c:a1e0:ab12:4843:cd96:6253:2482";
|
2023-03-12 03:15:34 +00:00
|
|
|
my.coredns.bind = [ "bond0" "tailscale0" "127.0.0.1" "::1" ];
|
2023-01-17 22:09:48 +00:00
|
|
|
|
|
|
|
services.openssh.hostKeys = [
|
|
|
|
{
|
|
|
|
path = "/persist/etc/ssh/ssh_host_ed25519_key";
|
|
|
|
type = "ed25519";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
path = "/persist/etc/ssh/ssh_host_rsa_key";
|
|
|
|
type = "rsa";
|
|
|
|
bits = 4096;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.mounts = let
|
|
|
|
bindMount' = dir: {
|
|
|
|
unitConfig.RequiresMountsFor = dir;
|
|
|
|
options = "bind";
|
|
|
|
what = "/persist${dir}";
|
|
|
|
where = dir;
|
|
|
|
};
|
|
|
|
bindMountSvc = dir: svc: (bindMount' dir) // {
|
2023-08-17 02:50:57 +00:00
|
|
|
requiredBy = [svc];
|
|
|
|
before = [svc];
|
|
|
|
wantedBy = ["multi-user.target"];
|
2023-01-17 22:09:48 +00:00
|
|
|
};
|
|
|
|
bindMountSvcDynamic = dir: svc: (bindMount' "/var/lib/private/${dir}") // {
|
|
|
|
requiredBy = [svc];
|
|
|
|
before = [svc];
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
};
|
|
|
|
bindMount = dir: (bindMount' dir) // {
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
};
|
|
|
|
in [
|
|
|
|
(bindMountSvc "/var/lib/tailscale" "tailscaled.service")
|
2023-03-12 21:58:43 +00:00
|
|
|
(bindMountSvc "/var/lib/private/factorio" "factorio.service")
|
2024-03-24 23:25:15 +00:00
|
|
|
(bindMountSvc "/var/lib/libvirt" "libvirt.service")
|
2023-01-17 22:09:48 +00:00
|
|
|
];
|
|
|
|
|
2023-01-18 23:41:42 +00:00
|
|
|
services.lukegbgp = let
|
|
|
|
local.asn = 205479;
|
|
|
|
in {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
local = {
|
|
|
|
routerID = "199.19.152.160";
|
|
|
|
};
|
|
|
|
export.v4 = [ ];
|
2023-01-19 09:29:37 +00:00
|
|
|
export.v6 = [ "2a09:a446:1337::/48" ];
|
2023-01-18 23:41:42 +00:00
|
|
|
peering.cofractal = {
|
|
|
|
local = local // {
|
|
|
|
v6 = "2a09:a446:1337:ffff::10";
|
|
|
|
};
|
2023-01-19 09:29:37 +00:00
|
|
|
v4onv6 = true;
|
2023-01-18 23:41:42 +00:00
|
|
|
remote = {
|
|
|
|
asn = 26073;
|
|
|
|
export_community = 6000;
|
|
|
|
routers = [{
|
|
|
|
v6 = "2a09:a446:1337:ffff::2";
|
|
|
|
} {
|
|
|
|
v6 = "2a09:a446:1337:ffff::3";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-05 12:34:40 +00:00
|
|
|
boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
|
|
|
|
|
2023-03-12 03:15:34 +00:00
|
|
|
services.sonarr.enable = true;
|
|
|
|
services.radarr.enable = true;
|
|
|
|
services.kubo = {
|
2023-04-15 00:41:49 +00:00
|
|
|
enable = false; # kubo is so expensive for no reason :/
|
2023-03-12 03:15:34 +00:00
|
|
|
settings = {
|
|
|
|
Discovery.MDNS.Enabled = false;
|
|
|
|
Swarm.DisableNatPortMap = true;
|
|
|
|
Experimental.FilestoreEnabled = true;
|
|
|
|
};
|
|
|
|
dataDir = "/store/ipfs";
|
|
|
|
};
|
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = vhosts;
|
|
|
|
};
|
|
|
|
|
2023-03-12 20:33:25 +00:00
|
|
|
services.factorio = {
|
|
|
|
inherit (depot.ops.secrets.factorio) username token;
|
|
|
|
enable = true;
|
|
|
|
saveName = "lukegb20230312-krastorio2";
|
|
|
|
game-name = "Briefcase Full of Bees";
|
|
|
|
mods = depot.nix.pkgs.factorio-mods._all;
|
2023-03-12 21:58:43 +00:00
|
|
|
mods-dat = ./mod-settings.dat;
|
2024-03-24 23:25:15 +00:00
|
|
|
admins = ["lukegb"];
|
2023-03-12 20:33:25 +00:00
|
|
|
extraSettings = {
|
|
|
|
auto_pause = true;
|
|
|
|
only_admins_can_pause_the_game = false;
|
|
|
|
game_password = depot.ops.secrets.factorioServerPassword;
|
|
|
|
non_blocking_saving = true;
|
|
|
|
autosave_only_on_server = true;
|
|
|
|
autosave_interval = 5;
|
|
|
|
autosave_slots = 60;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-05-11 10:27:15 +00:00
|
|
|
virtualisation.libvirtd = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
security.polkit.enable = true;
|
|
|
|
users.users.lukegb.extraGroups = lib.mkAfter [ "libvirtd" ];
|
|
|
|
|
2023-01-17 22:09:48 +00:00
|
|
|
system.stateVersion = "23.05";
|
|
|
|
}
|