2020-12-26 23:36:34 +00:00
|
|
|
# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
{ depot, lib, pkgs, rebuilder, config, ... }:
|
|
|
|
let
|
|
|
|
inherit (depot.ops) secrets;
|
|
|
|
machineSecrets = secrets.machineSpecific.etheroute-lon01;
|
|
|
|
in {
|
|
|
|
imports = [
|
|
|
|
../lib/bgp.nix
|
|
|
|
../lib/zfs.nix
|
2020-12-28 14:08:24 +00:00
|
|
|
|
|
|
|
../../../nix/pkgs/pomerium/module.nix
|
2020-12-26 23:36:34 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
boot.initrd = {
|
|
|
|
availableKernelModules = [
|
|
|
|
"ehci_pci"
|
|
|
|
"ahci"
|
|
|
|
"usbhid"
|
|
|
|
"usb_storage"
|
|
|
|
"sd_mod"
|
|
|
|
"sr_mod"
|
|
|
|
"bnx2" # ethernet
|
|
|
|
];
|
|
|
|
network = {
|
|
|
|
enable = true;
|
|
|
|
ssh = {
|
|
|
|
enable = true;
|
|
|
|
hostKeys = ["/persist/etc/ssh/ssh_host_ed25519_key"];
|
|
|
|
authorizedKeys = map builtins.readFile config.users.users.lukegb.openssh.authorizedKeys.keyFiles;
|
|
|
|
};
|
|
|
|
postCommands = ''
|
|
|
|
echo "zfs load-key -a; killall zfs" >> /root/.profile
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
boot.kernelParams = [
|
|
|
|
"ip=83.97.19.68::83.97.19.65:255.255.255.224:etheroute-lon01:eno1:none"
|
|
|
|
];
|
|
|
|
boot.kernelModules = [ "kvm-intel" ];
|
|
|
|
|
|
|
|
# Use the systemd-boot EFI boot loader.
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
|
|
|
|
powerManagement.cpuFreqGovernor = lib.mkDefault "performance";
|
|
|
|
services.zfs.rollbackOnBoot = {
|
|
|
|
enable = true;
|
|
|
|
snapshot = "tank/local/root@blank";
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSystems = let
|
|
|
|
zfs = device: {
|
|
|
|
device = device;
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
"/" = zfs "tank/local/root";
|
|
|
|
"/nix" = zfs "tank/local/nix";
|
|
|
|
"/tmp" = zfs "tank/local/tmp";
|
|
|
|
|
|
|
|
"/persist" = zfs "tank/safe/persist";
|
|
|
|
"/home" = zfs "tank/safe/home";
|
|
|
|
|
|
|
|
"/boot" = {
|
|
|
|
device = "/dev/disk/by-partlabel/ESP";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
nix.maxJobs = lib.mkDefault 8;
|
|
|
|
|
|
|
|
# Networking!
|
|
|
|
networking = {
|
|
|
|
hostName = "etheroute-lon01";
|
|
|
|
domain = "as205479.net";
|
|
|
|
hostId = "420bee1b";
|
|
|
|
|
|
|
|
nameservers = [
|
|
|
|
"2001:4860:4860::8888"
|
|
|
|
"2001:4860:4860::8844"
|
|
|
|
"8.8.8.8"
|
|
|
|
"8.8.4.4"
|
|
|
|
];
|
|
|
|
useDHCP = false;
|
|
|
|
defaultGateway = {
|
|
|
|
address = "83.97.19.65";
|
|
|
|
interface = "eno1";
|
|
|
|
};
|
|
|
|
defaultGateway6 = {
|
|
|
|
address = "2a07:242:800:64::1";
|
|
|
|
interface = "eno1";
|
|
|
|
};
|
|
|
|
interfaces.eno1 = {
|
|
|
|
ipv4.addresses = [{ address = "83.97.19.68"; prefixLength = 27; }];
|
|
|
|
ipv6.addresses = [{ address = "2a07:242:800:64::68"; prefixLength = 64; }];
|
|
|
|
};
|
2020-12-28 15:27:18 +00:00
|
|
|
firewall.allowedTCPPorts = [ 80 443 ];
|
2020-12-26 23:36:34 +00:00
|
|
|
};
|
|
|
|
my.ip.tailscale = "100.111.191.21";
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
users.users = {
|
|
|
|
lukegb.extraGroups = [ "bird2" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.lukegbgp = let local = {
|
|
|
|
asn = 205479;
|
|
|
|
}; in {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
local = {
|
|
|
|
routerID = "83.97.19.68";
|
|
|
|
};
|
|
|
|
peering = {
|
|
|
|
etheroute = {
|
|
|
|
local = local // {
|
|
|
|
v4 = "83.97.19.68";
|
|
|
|
v6 = "2a07:242:800:64::68";
|
|
|
|
};
|
|
|
|
remote = {
|
|
|
|
asn = 16089;
|
|
|
|
export_community = 4000;
|
|
|
|
routers = [{
|
|
|
|
v4 = "83.97.19.65";
|
|
|
|
v6 = "2a07:242:800:64::1";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.mounts = let
|
|
|
|
bindMount' = dir: {
|
|
|
|
unitConfig.RequiresMountsFor = dir;
|
|
|
|
options = "bind";
|
|
|
|
what = "/persist${dir}";
|
|
|
|
where = dir;
|
|
|
|
};
|
|
|
|
bindMountSvc = dir: svc: (bindMount' dir) // {
|
|
|
|
bindsTo = [svc];
|
|
|
|
partOf = [svc];
|
|
|
|
};
|
|
|
|
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")
|
|
|
|
];
|
|
|
|
|
2020-12-28 19:09:55 +00:00
|
|
|
services.redis = {
|
|
|
|
enable = true;
|
|
|
|
bind = "127.0.0.1";
|
|
|
|
};
|
2020-12-28 14:08:24 +00:00
|
|
|
services.pomerium = {
|
|
|
|
enable = true;
|
|
|
|
secretsFile = machineSecrets.pomeriumSecrets;
|
2020-12-28 18:54:00 +00:00
|
|
|
|
|
|
|
config = {
|
|
|
|
address = ":443";
|
|
|
|
http_redirect_addr = ":80";
|
|
|
|
|
|
|
|
idp_provider = "google";
|
|
|
|
idp_client_id = "136257844546-qsa6hi1oqqoq2bnt93deo4e70ggbn1p8.apps.googleusercontent.com";
|
|
|
|
|
2020-12-28 19:09:55 +00:00
|
|
|
databroker_storage_type = "redis";
|
2020-12-28 19:11:25 +00:00
|
|
|
databroker_storage_connection_string = "redis://127.0.0.1:6379/15";
|
2020-12-28 19:09:55 +00:00
|
|
|
|
2020-12-28 18:54:00 +00:00
|
|
|
forward_auth_url = "https://fwdauth.int.lukegb.com";
|
|
|
|
authenticate_service_url = "https://auth.int.lukegb.com";
|
|
|
|
|
|
|
|
policy = let
|
|
|
|
baseConfig = {
|
|
|
|
allowed_domains = [ "lukegb.com" ];
|
|
|
|
};
|
|
|
|
serviceOnHost = server: hostName: baseConfig // {
|
|
|
|
from = "https://${hostName}";
|
|
|
|
to = "http://${server}";
|
|
|
|
preserve_host_header = true;
|
|
|
|
pass_identity_headers = true;
|
|
|
|
};
|
|
|
|
hostToServices = {
|
|
|
|
clouvider-fra01 = [
|
|
|
|
"int.lukegb.com"
|
|
|
|
"sonarr.int.lukegb.com"
|
|
|
|
"radarr.int.lukegb.com"
|
|
|
|
"deluge.int.lukegb.com"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
servicesOnHosts = lib.concatLists (lib.mapAttrsToList (hostName: services: map (serviceOnHost hostName) services) hostToServices);
|
|
|
|
in servicesOnHosts ++ [
|
|
|
|
(baseConfig // {
|
|
|
|
from = "https://httpbin.int.lukegb.com";
|
|
|
|
to = "https://verify.pomerium.com";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
2020-12-28 14:08:24 +00:00
|
|
|
};
|
|
|
|
systemd.services.pomerium.serviceConfig = {
|
2020-12-28 19:09:55 +00:00
|
|
|
After = [ "acme-finished-int.lukegb.com.target" "redis.service" ];
|
|
|
|
Wants = [ "acme-finished-int.lukegb.com.target" "redis.service" ];
|
2020-12-28 15:27:18 +00:00
|
|
|
LoadCredential = [
|
2020-12-28 14:08:24 +00:00
|
|
|
"certfullchain.pem:/var/lib/acme/int.lukegb.com/fullchain.pem"
|
|
|
|
"certkey.pem:/var/lib/acme/int.lukegb.com/key.pem"
|
|
|
|
];
|
|
|
|
Environment = [
|
2020-12-28 15:27:18 +00:00
|
|
|
"CERTIFICATE_FILE=certfullchain.pem"
|
|
|
|
"CERTIFICATE_KEY_FILE=certkey.pem"
|
2020-12-28 14:08:24 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
security.acme = {
|
|
|
|
acceptTerms = true;
|
|
|
|
email = "letsencrypt@lukegb.com";
|
|
|
|
certs."int.lukegb.com" = {
|
|
|
|
domain = "*.int.lukegb.com";
|
|
|
|
dnsProvider = "cloudflare";
|
|
|
|
credentialsFile = secrets.cloudflareCredentials;
|
|
|
|
extraDomainNames = ["int.lukegb.com"];
|
|
|
|
postRun = ''
|
|
|
|
systemctl restart pomerium
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-12-26 23:36:34 +00:00
|
|
|
system.stateVersion = "20.09";
|
|
|
|
}
|