2021-04-11 22:50:30 +02:00
|
|
|
{ depot, lib, pkgs, ... }: # readTree options
|
2021-04-11 21:57:00 +02:00
|
|
|
{ config, ... }: # passed by module system
|
2020-07-02 20:19:08 +02:00
|
|
|
|
|
|
|
let
|
2020-07-02 21:27:02 +02:00
|
|
|
inherit (builtins) listToAttrs;
|
|
|
|
inherit (lib) range;
|
2022-05-26 14:33:44 +02:00
|
|
|
|
|
|
|
mod = name: depot.path.origSrc + ("/ops/modules/" + name);
|
2022-01-30 17:06:58 +01:00
|
|
|
in
|
|
|
|
{
|
2020-07-02 20:19:08 +02:00
|
|
|
imports = [
|
2022-05-26 14:33:44 +02:00
|
|
|
(mod "atward.nix")
|
|
|
|
(mod "cgit/default.nix")
|
|
|
|
(mod "clbot.nix")
|
|
|
|
(mod "gerrit-queue.nix")
|
|
|
|
(mod "irccat.nix")
|
|
|
|
(mod "josh.nix")
|
|
|
|
(mod "journaldriver.nix")
|
|
|
|
(mod "known-hosts.nix")
|
|
|
|
(mod "monorepo-gerrit.nix")
|
|
|
|
(mod "nixery.nix")
|
|
|
|
(mod "oauth2_proxy.nix")
|
|
|
|
(mod "owothia.nix")
|
|
|
|
(mod "panettone.nix")
|
|
|
|
(mod "paroxysm.nix")
|
|
|
|
(mod "restic.nix")
|
|
|
|
(mod "smtprelay.nix")
|
|
|
|
(mod "sourcegraph.nix")
|
|
|
|
(mod "tvl-buildkite.nix")
|
|
|
|
(mod "tvl-slapd/default.nix")
|
|
|
|
(mod "tvl-users.nix")
|
|
|
|
(mod "www/atward.tvl.fyi.nix")
|
|
|
|
(mod "www/auth.tvl.fyi.nix")
|
|
|
|
(mod "www/b.tvl.fyi.nix")
|
|
|
|
(mod "www/cache.tvl.su.nix")
|
|
|
|
(mod "www/cl.tvl.fyi.nix")
|
|
|
|
(mod "www/code.tvl.fyi.nix")
|
|
|
|
(mod "www/cs.tvl.fyi.nix")
|
|
|
|
(mod "www/deploys.tvl.fyi.nix")
|
|
|
|
(mod "www/images.tvl.fyi.nix")
|
|
|
|
(mod "www/nixery.dev.nix")
|
|
|
|
(mod "www/self-redirect.nix")
|
|
|
|
(mod "www/static.tvl.fyi.nix")
|
|
|
|
(mod "www/status.tvl.su.nix")
|
|
|
|
(mod "www/tazj.in.nix")
|
|
|
|
(mod "www/todo.tvl.fyi.nix")
|
|
|
|
(mod "www/tvl.fyi.nix")
|
|
|
|
(mod "www/tvl.su.nix")
|
|
|
|
(mod "www/wigglydonke.rs.nix")
|
|
|
|
|
|
|
|
(depot.third_party.agenix.src + "/modules/age.nix")
|
2020-07-02 20:19:08 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
hardware = {
|
|
|
|
enableRedistributableFirmware = true;
|
|
|
|
cpu.amd.updateMicrocode = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
boot = {
|
|
|
|
tmpOnTmpfs = true;
|
|
|
|
kernelModules = [ "kvm-amd" ];
|
|
|
|
supportedFilesystems = [ "zfs" ];
|
|
|
|
|
|
|
|
initrd = {
|
|
|
|
availableKernelModules = [
|
2022-01-30 17:06:58 +01:00
|
|
|
"igb"
|
|
|
|
"xhci_pci"
|
|
|
|
"nvme"
|
|
|
|
"ahci"
|
|
|
|
"usbhid"
|
|
|
|
"usb_storage"
|
|
|
|
"sr_mod"
|
2020-07-02 20:19:08 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
# Enable SSH in the initrd so that we can enter disk encryption
|
|
|
|
# passwords remotely.
|
|
|
|
network = {
|
|
|
|
enable = true;
|
|
|
|
ssh = {
|
|
|
|
enable = true;
|
|
|
|
port = 2222;
|
2020-12-20 18:06:09 +01:00
|
|
|
authorizedKeys =
|
|
|
|
depot.users.tazjin.keys.all
|
|
|
|
++ depot.users.lukegb.keys.all
|
2021-04-11 23:53:27 +02:00
|
|
|
++ [ depot.users.grfn.keys.whitby ];
|
2020-07-02 20:19:08 +02:00
|
|
|
|
|
|
|
hostKeys = [
|
|
|
|
/etc/secrets/initrd_host_ed25519_key
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# this will launch the zfs password prompt on login and kill the
|
|
|
|
# other prompt
|
|
|
|
postCommands = ''
|
|
|
|
echo "zfs load-key -a && killall zfs" >> /root/.profile
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-26 00:44:08 +01:00
|
|
|
kernel.sysctl = {
|
|
|
|
"net.ipv4.tcp_congestion_control" = "bbr";
|
|
|
|
};
|
|
|
|
|
2020-07-02 20:19:08 +02:00
|
|
|
loader.grub = {
|
|
|
|
enable = true;
|
|
|
|
version = 2;
|
|
|
|
efiSupport = true;
|
|
|
|
efiInstallAsRemovable = true;
|
|
|
|
device = "/dev/disk/by-id/nvme-SAMSUNG_MZQLB1T9HAJR-00007_S439NA0N201620";
|
|
|
|
};
|
|
|
|
|
|
|
|
zfs.requestEncryptionCredentials = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSystems = {
|
|
|
|
"/" = {
|
|
|
|
device = "zroot/root";
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
|
|
|
|
|
|
|
"/boot" = {
|
|
|
|
device = "/dev/disk/by-uuid/073E-7FBD";
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
|
|
|
|
|
|
|
"/nix" = {
|
|
|
|
device = "zroot/nix";
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
|
|
|
|
|
|
|
"/home" = {
|
|
|
|
device = "zroot/home";
|
|
|
|
fsType = "zfs";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking = {
|
|
|
|
# Glass is boring, but Luke doesn't like Wapping - the Prospect of
|
|
|
|
# Whitby, however, is quite a pleasant establishment.
|
|
|
|
hostName = "whitby";
|
2020-07-18 00:25:20 +02:00
|
|
|
domain = "tvl.fyi";
|
2020-07-02 20:19:08 +02:00
|
|
|
hostId = "b38ca543";
|
|
|
|
useDHCP = false;
|
2020-07-02 21:27:23 +02:00
|
|
|
|
2020-07-18 00:25:20 +02:00
|
|
|
# Don't use Hetzner's DNS servers.
|
|
|
|
nameservers = [
|
|
|
|
"8.8.8.8"
|
|
|
|
"8.8.4.4"
|
|
|
|
];
|
|
|
|
|
2020-07-02 21:27:23 +02:00
|
|
|
defaultGateway6 = {
|
|
|
|
address = "fe80::1";
|
|
|
|
interface = "enp196s0";
|
|
|
|
};
|
2020-07-02 20:19:08 +02:00
|
|
|
|
2021-05-21 13:11:46 +02:00
|
|
|
firewall.allowedTCPPorts = [ 22 80 443 4238 8443 29418 ];
|
|
|
|
firewall.allowedUDPPorts = [ 8443 ];
|
2020-07-02 20:19:08 +02:00
|
|
|
|
|
|
|
interfaces.enp196s0.useDHCP = true;
|
|
|
|
interfaces.enp196s0.ipv6.addresses = [
|
|
|
|
{
|
|
|
|
address = "2a01:04f8:0242:5b21::feed:edef:beef";
|
|
|
|
prefixLength = 64;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2020-07-18 00:25:20 +02:00
|
|
|
# Generate an immutable /etc/resolv.conf from the nameserver settings
|
|
|
|
# above (otherwise DHCP overwrites it):
|
|
|
|
environment.etc."resolv.conf" = with lib; {
|
2021-04-10 18:05:16 +02:00
|
|
|
source = pkgs.writeText "resolv.conf" ''
|
2021-04-12 17:59:51 +02:00
|
|
|
${concatStringsSep "\n" (map (ns: "nameserver ${ns}") config.networking.nameservers)}
|
2020-07-18 00:25:20 +02:00
|
|
|
options edns0
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-12-20 17:55:38 +01:00
|
|
|
# Disable background git gc system-wide, as it has a tendency to break CI.
|
2021-04-10 18:05:16 +02:00
|
|
|
environment.etc."gitconfig".source = pkgs.writeText "gitconfig" ''
|
2020-12-20 17:55:38 +01:00
|
|
|
[gc]
|
|
|
|
autoDetach = false
|
|
|
|
'';
|
|
|
|
|
2020-07-02 20:19:08 +02:00
|
|
|
time.timeZone = "UTC";
|
|
|
|
|
|
|
|
nix = {
|
2020-12-26 15:23:26 +01:00
|
|
|
nrBuildUsers = 256;
|
2020-07-02 20:19:08 +02:00
|
|
|
maxJobs = lib.mkDefault 64;
|
2020-07-02 21:07:58 +02:00
|
|
|
extraOptions = ''
|
2021-12-10 19:23:05 +01:00
|
|
|
secret-key-files = /run/agenix/nix-cache-priv
|
2020-07-02 21:07:58 +02:00
|
|
|
'';
|
2020-07-02 23:31:15 +02:00
|
|
|
|
|
|
|
trustedUsers = [
|
|
|
|
"grfn"
|
2020-07-04 22:11:30 +02:00
|
|
|
"lukegb"
|
2020-08-06 02:18:04 +02:00
|
|
|
"tazjin"
|
2021-03-25 20:59:31 +01:00
|
|
|
"sterni"
|
2020-07-02 23:31:15 +02:00
|
|
|
];
|
2020-07-03 16:22:21 +02:00
|
|
|
|
|
|
|
sshServe = {
|
|
|
|
enable = true;
|
|
|
|
keys = with depot.users;
|
|
|
|
tazjin.keys.all
|
|
|
|
++ lukegb.keys.all
|
2021-04-11 23:53:27 +02:00
|
|
|
++ [ grfn.keys.whitby ]
|
2021-03-25 20:59:31 +01:00
|
|
|
++ sterni.keys.all
|
2022-01-30 17:06:58 +01:00
|
|
|
;
|
2020-07-03 16:22:21 +02:00
|
|
|
};
|
2020-07-02 20:19:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
programs.mtr.enable = true;
|
2020-08-14 20:17:33 +02:00
|
|
|
programs.mosh.enable = true;
|
2020-08-13 00:15:35 +02:00
|
|
|
services.openssh = {
|
|
|
|
enable = true;
|
|
|
|
passwordAuthentication = false;
|
|
|
|
challengeResponseAuthentication = false;
|
|
|
|
};
|
2020-07-02 20:19:08 +02:00
|
|
|
|
2021-12-09 14:53:22 +01:00
|
|
|
# Configure secrets for services that need them.
|
2021-12-10 07:58:16 +01:00
|
|
|
age.secrets =
|
|
|
|
let
|
2021-12-12 09:14:50 +01:00
|
|
|
secretFile = name: depot.ops.secrets."${name}.age";
|
2022-01-30 17:06:58 +01:00
|
|
|
in
|
|
|
|
{
|
2021-12-10 07:58:16 +01:00
|
|
|
clbot.file = secretFile "clbot";
|
|
|
|
gerrit-queue.file = secretFile "gerrit-queue";
|
2021-12-10 13:55:08 +01:00
|
|
|
grafana.file = secretFile "grafana";
|
2021-12-10 15:10:50 +01:00
|
|
|
irccat.file = secretFile "irccat";
|
2021-12-25 15:06:15 +01:00
|
|
|
keycloak-db.file = secretFile "keycloak-db";
|
2021-12-10 19:23:05 +01:00
|
|
|
nix-cache-priv.file = secretFile "nix-cache-priv";
|
2022-01-04 12:28:58 +01:00
|
|
|
oauth2_proxy.file = secretFile "oauth2_proxy";
|
2021-12-10 21:19:56 +01:00
|
|
|
owothia.file = secretFile "owothia";
|
|
|
|
panettone.file = secretFile "panettone";
|
2022-01-01 14:38:14 +01:00
|
|
|
smtprelay.file = secretFile "smtprelay";
|
2021-12-10 08:29:41 +01:00
|
|
|
|
|
|
|
buildkite-agent-token = {
|
|
|
|
file = secretFile "buildkite-agent-token";
|
|
|
|
mode = "0440";
|
|
|
|
group = "buildkite-agents";
|
|
|
|
};
|
2021-12-10 13:32:11 +01:00
|
|
|
|
2021-12-10 14:11:19 +01:00
|
|
|
buildkite-graphql-token = {
|
|
|
|
file = secretFile "buildkite-graphql-token";
|
|
|
|
mode = "0440";
|
2021-12-10 21:01:20 +01:00
|
|
|
group = "buildkite-agents";
|
2021-12-10 14:11:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
buildkite-besadii-config = {
|
|
|
|
file = secretFile "besadii";
|
|
|
|
mode = "0440";
|
2021-12-10 21:01:20 +01:00
|
|
|
group = "buildkite-agents";
|
2021-12-10 14:11:19 +01:00
|
|
|
};
|
|
|
|
|
2022-05-25 18:17:25 +02:00
|
|
|
buildkite-private-key = {
|
|
|
|
file = secretFile "buildkite-ssh-private-key";
|
|
|
|
mode = "0440";
|
|
|
|
group = "buildkite-agents";
|
|
|
|
};
|
|
|
|
|
2021-12-10 14:11:19 +01:00
|
|
|
gerrit-besadii-config = {
|
|
|
|
file = secretFile "besadii";
|
|
|
|
owner = "git";
|
|
|
|
};
|
|
|
|
|
2021-12-25 22:03:41 +01:00
|
|
|
gerrit-secrets = {
|
|
|
|
file = secretFile "gerrit-secrets";
|
|
|
|
path = "/var/lib/gerrit/etc/secure.config";
|
|
|
|
owner = "git";
|
|
|
|
mode = "0400";
|
|
|
|
};
|
|
|
|
|
2021-12-10 13:32:11 +01:00
|
|
|
clbot-ssh = {
|
|
|
|
file = secretFile "clbot-ssh";
|
|
|
|
owner = "clbot";
|
|
|
|
};
|
2021-12-10 19:23:05 +01:00
|
|
|
|
|
|
|
# Not actually a secret
|
|
|
|
nix-cache-pub = {
|
|
|
|
file = secretFile "nix-cache-pub";
|
|
|
|
mode = "0444";
|
|
|
|
};
|
2021-12-10 07:58:16 +01:00
|
|
|
};
|
2021-12-09 14:53:22 +01:00
|
|
|
|
2021-04-14 18:16:42 +02:00
|
|
|
# Automatically collect garbage from the Nix store.
|
|
|
|
services.depot.automatic-gc = {
|
|
|
|
enable = true;
|
|
|
|
interval = "1 hour";
|
|
|
|
diskThreshold = 200; # GiB
|
|
|
|
maxFreed = 420; # GiB
|
|
|
|
preserveGenerations = "90d";
|
|
|
|
};
|
|
|
|
|
2020-07-02 21:27:02 +02:00
|
|
|
# Run a handful of Buildkite agents to support parallel builds.
|
2021-04-09 19:04:50 +02:00
|
|
|
services.depot.buildkite = {
|
|
|
|
enable = true;
|
|
|
|
agentCount = 32;
|
|
|
|
};
|
2020-07-02 21:27:02 +02:00
|
|
|
|
2020-07-11 13:51:04 +02:00
|
|
|
# Start a local SMTP relay to Gmail (used by gerrit)
|
|
|
|
services.depot.smtprelay = {
|
|
|
|
enable = true;
|
|
|
|
args = {
|
|
|
|
listen = ":2525";
|
|
|
|
remote_host = "smtp.gmail.com:587";
|
|
|
|
remote_auth = "plain";
|
|
|
|
remote_user = "tvlbot@tazj.in";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-05-21 01:09:14 +02:00
|
|
|
# Start a ZNC instance which bounces for tvlbot and owothia.
|
|
|
|
services.znc = {
|
|
|
|
enable = true;
|
|
|
|
useLegacyConfig = false;
|
|
|
|
config = {
|
|
|
|
LoadModule = [
|
|
|
|
"webadmin"
|
|
|
|
"adminlog"
|
|
|
|
];
|
|
|
|
|
|
|
|
User.admin = {
|
|
|
|
Admin = true;
|
|
|
|
Pass.password = {
|
|
|
|
Method = "sha256";
|
|
|
|
Hash = "bb00aa8239de484c2925b1c3f6a196fb7612633f001daa9b674f83abe7e1103f";
|
|
|
|
Salt = "TiB0Ochb1CrtpMTl;2;j";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Listener.l = {
|
|
|
|
Host = "localhost";
|
|
|
|
Port = 2627; # bncr
|
|
|
|
SSL = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-11 14:03:34 +02:00
|
|
|
# Start the Gerrit->IRC bot
|
|
|
|
services.depot.clbot = {
|
|
|
|
enable = true;
|
2021-05-22 15:22:03 +02:00
|
|
|
channels = [ "#tvl" ];
|
2020-07-11 14:03:34 +02:00
|
|
|
|
2021-05-22 15:22:03 +02:00
|
|
|
# See //fun/clbot for details.
|
2020-07-11 14:03:34 +02:00
|
|
|
flags = {
|
|
|
|
gerrit_host = "cl.tvl.fyi:29418";
|
|
|
|
gerrit_ssh_auth_username = "clbot";
|
2022-05-22 23:51:49 +02:00
|
|
|
gerrit_ssh_auth_key = config.age.secretsDir + "/clbot-ssh";
|
2021-05-22 15:22:03 +02:00
|
|
|
|
|
|
|
irc_server = "localhost:${toString config.services.znc.config.Listener.l.Port}";
|
|
|
|
irc_user = "tvlbot";
|
|
|
|
irc_nick = "tvlbot";
|
2020-07-11 14:03:34 +02:00
|
|
|
|
|
|
|
notify_branches = "canon,refs/meta/config";
|
|
|
|
notify_repo = "depot";
|
|
|
|
|
|
|
|
# This secret is read from an environment variable, which is
|
2021-12-10 13:32:11 +01:00
|
|
|
# populated by a systemd EnvironmentFile.
|
2020-07-11 14:03:34 +02:00
|
|
|
irc_pass = "$CLBOT_PASS";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-22 01:40:49 +02:00
|
|
|
services.depot = {
|
|
|
|
# Run a SourceGraph code search instance
|
|
|
|
sourcegraph.enable = true;
|
|
|
|
|
|
|
|
# Run the Panettone issue tracker
|
2020-07-26 21:41:15 +02:00
|
|
|
panettone = {
|
|
|
|
enable = true;
|
|
|
|
dbUser = "panettone";
|
|
|
|
dbName = "panettone";
|
2021-05-22 17:05:45 +02:00
|
|
|
irccatChannel = "#tvl";
|
2020-07-26 21:41:15 +02:00
|
|
|
};
|
2020-07-31 23:30:52 +02:00
|
|
|
|
|
|
|
# Run the first cursed bot (quote bot)
|
|
|
|
paroxysm.enable = true;
|
2020-11-08 03:16:16 +01:00
|
|
|
|
2021-05-22 15:44:44 +02:00
|
|
|
# Run the second cursed bot
|
|
|
|
owothia = {
|
|
|
|
enable = true;
|
|
|
|
ircServer = "localhost";
|
|
|
|
ircPort = config.services.znc.config.Listener.l.Port;
|
|
|
|
};
|
|
|
|
|
2020-11-08 03:16:16 +01:00
|
|
|
# Run irccat to forward messages to IRC
|
|
|
|
irccat = {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
tcp.listen = ":4722"; # "ircc"
|
|
|
|
irc = {
|
2021-05-22 17:05:45 +02:00
|
|
|
server = "localhost:${toString config.services.znc.config.Listener.l.Port}";
|
|
|
|
tls = false;
|
2020-11-08 03:16:16 +01:00
|
|
|
nick = "tvlbot";
|
2021-05-23 22:30:23 +02:00
|
|
|
# Note: irccat means 'ident' where it says 'realname', so
|
|
|
|
# this is critical for connecting to ZNC.
|
|
|
|
realname = "tvlbot";
|
2020-11-08 03:16:16 +01:00
|
|
|
channels = [
|
2021-05-22 17:05:45 +02:00
|
|
|
"#tvl"
|
2020-11-08 03:16:16 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-05-04 00:43:08 +02:00
|
|
|
|
|
|
|
# Run atward, the search engine redirection thing.
|
|
|
|
atward.enable = true;
|
2021-08-06 13:53:41 +02:00
|
|
|
|
|
|
|
# Run a Nixery instance
|
|
|
|
nixery.enable = true;
|
2021-09-16 17:46:17 +02:00
|
|
|
|
|
|
|
# Run cgit & josh to serve git
|
2022-02-16 19:30:17 +01:00
|
|
|
cgit.enable = true;
|
2022-02-16 19:34:18 +01:00
|
|
|
josh.enable = true;
|
2021-09-16 20:47:25 +02:00
|
|
|
|
2021-11-20 17:32:11 +01:00
|
|
|
# Configure backups to GleSYS
|
2021-09-16 20:47:25 +02:00
|
|
|
restic = {
|
|
|
|
enable = true;
|
|
|
|
paths = [
|
|
|
|
"/var/backup/postgresql"
|
|
|
|
"/var/lib/grafana"
|
|
|
|
"/var/lib/znc"
|
|
|
|
];
|
|
|
|
};
|
2021-12-09 14:45:06 +01:00
|
|
|
|
|
|
|
# Run autosubmit bot for Gerrit
|
|
|
|
gerrit-queue.enable = true;
|
2022-01-04 12:28:58 +01:00
|
|
|
|
|
|
|
# Run oauth2_proxy for internal service auth
|
|
|
|
oauth2_proxy.enable = true;
|
2020-07-26 21:41:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
enableTCPIP = true;
|
|
|
|
|
2020-07-28 03:30:47 +02:00
|
|
|
authentication = lib.mkForce ''
|
2020-07-26 21:41:15 +02:00
|
|
|
local all all trust
|
2020-07-28 03:30:47 +02:00
|
|
|
host all all 127.0.0.1/32 password
|
|
|
|
host all all ::1/128 password
|
|
|
|
hostnossl all all 127.0.0.1/32 password
|
|
|
|
hostnossl all all ::1/128 password
|
2020-07-26 21:41:15 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
ensureDatabases = [
|
|
|
|
"panettone"
|
|
|
|
];
|
|
|
|
|
|
|
|
ensureUsers = [{
|
|
|
|
name = "panettone";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE panettone" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}];
|
2020-07-22 01:40:49 +02:00
|
|
|
};
|
2020-07-12 13:54:16 +02:00
|
|
|
|
2020-08-01 18:41:30 +02:00
|
|
|
services.postgresqlBackup = {
|
|
|
|
enable = true;
|
|
|
|
databases = [
|
2021-12-25 15:06:15 +01:00
|
|
|
"keycloak"
|
2020-08-01 18:41:30 +02:00
|
|
|
"panettone"
|
2021-12-25 15:06:15 +01:00
|
|
|
"tvldb"
|
2020-08-01 18:41:30 +02:00
|
|
|
];
|
|
|
|
};
|
2020-07-26 21:41:15 +02:00
|
|
|
|
2021-04-04 20:24:34 +02:00
|
|
|
services.nix-serve = {
|
|
|
|
enable = true;
|
|
|
|
port = 6443;
|
2022-05-22 23:51:49 +02:00
|
|
|
secretKeyFile = config.age.secretsDir + "/nix-cache-priv";
|
2021-04-04 20:24:34 +02:00
|
|
|
bindAddress = "localhost";
|
|
|
|
};
|
|
|
|
|
2021-05-23 14:03:19 +02:00
|
|
|
services.fail2ban.enable = true;
|
|
|
|
|
2022-01-13 09:15:43 +01:00
|
|
|
environment.systemPackages = (with pkgs; [
|
|
|
|
bat
|
2020-07-02 20:19:08 +02:00
|
|
|
bb
|
|
|
|
curl
|
2021-12-13 13:47:13 +01:00
|
|
|
direnv
|
2020-07-02 20:19:08 +02:00
|
|
|
emacs-nox
|
2022-01-13 09:15:43 +01:00
|
|
|
fd
|
2020-07-02 20:19:08 +02:00
|
|
|
git
|
|
|
|
htop
|
2022-01-13 09:15:43 +01:00
|
|
|
hyperfine
|
2021-12-13 13:47:13 +01:00
|
|
|
jq
|
2020-07-02 20:19:08 +02:00
|
|
|
nano
|
2022-01-13 09:15:43 +01:00
|
|
|
nvd
|
2021-12-13 13:47:13 +01:00
|
|
|
ripgrep
|
2022-01-13 09:15:43 +01:00
|
|
|
tree
|
|
|
|
unzip
|
2020-07-02 20:19:08 +02:00
|
|
|
vim
|
|
|
|
zfs
|
|
|
|
zfstools
|
2022-01-13 09:15:43 +01:00
|
|
|
]) ++ (with depot; [
|
|
|
|
ops.deploy-whitby
|
|
|
|
]);
|
2020-07-02 20:19:08 +02:00
|
|
|
|
2022-01-30 00:04:33 +01:00
|
|
|
# Required for prometheus to be able to scrape stats
|
|
|
|
services.nginx.statusPage = true;
|
|
|
|
|
2021-04-11 21:57:00 +02:00
|
|
|
# Configure Prometheus & Grafana. Exporter configuration for
|
|
|
|
# Prometheus is inside the respective service modules.
|
|
|
|
services.prometheus = {
|
|
|
|
enable = true;
|
2022-03-31 22:58:20 +02:00
|
|
|
retentionTime = "90d";
|
2021-04-11 21:57:00 +02:00
|
|
|
|
2022-01-29 23:49:47 +01:00
|
|
|
exporters = {
|
|
|
|
node = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
enabledCollectors = [
|
|
|
|
"logind"
|
|
|
|
"processes"
|
|
|
|
"systemd"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
nginx = {
|
|
|
|
enable = true;
|
|
|
|
sslVerify = false;
|
|
|
|
constLabels = [ "host=whitby" ];
|
|
|
|
};
|
2021-04-11 21:57:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
scrapeConfigs = [{
|
|
|
|
job_name = "node";
|
|
|
|
scrape_interval = "5s";
|
|
|
|
static_configs = [{
|
2022-01-30 17:06:58 +01:00
|
|
|
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ];
|
2021-04-11 21:57:00 +02:00
|
|
|
}];
|
2022-01-30 17:06:58 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
job_name = "nginx";
|
|
|
|
scrape_interval = "5s";
|
|
|
|
static_configs = [{
|
|
|
|
targets = [ "localhost:${toString config.services.prometheus.exporters.nginx.port}" ];
|
|
|
|
}];
|
2022-01-29 23:49:47 +01:00
|
|
|
}];
|
2021-04-11 21:57:00 +02:00
|
|
|
};
|
|
|
|
|
2021-04-12 17:59:51 +02:00
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
|
|
|
port = 4723; # "graf" on phone keyboard
|
|
|
|
domain = "status.tvl.su";
|
|
|
|
rootUrl = "https://status.tvl.su";
|
|
|
|
analytics.reporting.enable = false;
|
2022-01-30 17:06:58 +01:00
|
|
|
extraOptions =
|
|
|
|
let
|
|
|
|
options = {
|
|
|
|
auth = {
|
|
|
|
generic_oauth = {
|
|
|
|
enabled = true;
|
|
|
|
client_id = "grafana";
|
|
|
|
scopes = "openid profile email";
|
|
|
|
name = "TVL";
|
|
|
|
email_attribute_path = "mail";
|
|
|
|
login_attribute_path = "sub";
|
|
|
|
name_attribute_path = "displayName";
|
|
|
|
auth_url = "https://auth.tvl.fyi/auth/realms/TVL/protocol/openid-connect/auth";
|
|
|
|
token_url = "https://auth.tvl.fyi/auth/realms/TVL/protocol/openid-connect/token";
|
|
|
|
api_url = "https://auth.tvl.fyi/auth/realms/TVL/protocol/openid-connect/userinfo";
|
|
|
|
|
|
|
|
# Give lukegb, grfn, tazjin "Admin" rights.
|
|
|
|
role_attribute_path = "((sub == 'lukegb' || sub == 'grfn' || sub == 'tazjin') && 'Admin') || 'Editor'";
|
|
|
|
|
|
|
|
# Allow creating new Grafana accounts from OAuth accounts.
|
|
|
|
allow_sign_up = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
anonymous = {
|
|
|
|
enabled = true;
|
|
|
|
org_name = "The Virus Lounge";
|
|
|
|
org_role = "Viewer";
|
|
|
|
};
|
|
|
|
|
|
|
|
basic.enabled = false;
|
|
|
|
oauth_auto_login = true;
|
|
|
|
disable_login_form = true;
|
2021-04-13 01:32:40 +02:00
|
|
|
};
|
|
|
|
};
|
2022-01-30 17:06:58 +01:00
|
|
|
inherit (builtins) typeOf replaceStrings listToAttrs concatLists;
|
|
|
|
inherit (lib) toUpper mapAttrsToList nameValuePair concatStringsSep;
|
|
|
|
|
|
|
|
# Take ["auth" "generic_oauth" "enabled"] and turn it into OPTIONS_GENERIC_OAUTH_ENABLED.
|
|
|
|
encodeName = raw: replaceStrings [ "." ] [ "_" ] (toUpper (concatStringsSep "_" raw));
|
|
|
|
|
|
|
|
# Turn an option value into a string, but we want bools to be sensible strings and not "1" or "".
|
|
|
|
optionToString = value:
|
|
|
|
if (typeOf value) == "bool" then
|
|
|
|
if value then "true" else "false"
|
|
|
|
else builtins.toString value;
|
|
|
|
|
|
|
|
# Turn an nested options attrset into a flat listToAttrs-compatible list.
|
|
|
|
encodeOptions = prefix: inp: concatLists (mapAttrsToList
|
|
|
|
(name: value:
|
|
|
|
if (typeOf value) == "set"
|
|
|
|
then encodeOptions (prefix ++ [ name ]) value
|
|
|
|
else [ (nameValuePair (encodeName (prefix ++ [ name ])) (optionToString value)) ]
|
|
|
|
)
|
|
|
|
inp);
|
|
|
|
in
|
|
|
|
listToAttrs (encodeOptions [ ] options);
|
2021-04-12 17:59:51 +02:00
|
|
|
|
|
|
|
provision = {
|
|
|
|
enable = true;
|
|
|
|
datasources = [{
|
|
|
|
name = "Prometheus";
|
|
|
|
type = "prometheus";
|
|
|
|
url = "http://localhost:9090";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
2021-12-25 15:06:15 +01:00
|
|
|
|
2021-04-13 01:32:40 +02:00
|
|
|
# Contains GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET.
|
2022-05-22 23:51:49 +02:00
|
|
|
systemd.services.grafana.serviceConfig.EnvironmentFile = config.age.secretsDir + "/grafana";
|
2021-04-12 17:59:51 +02:00
|
|
|
|
2021-12-25 15:06:15 +01:00
|
|
|
services.keycloak = {
|
|
|
|
enable = true;
|
|
|
|
httpPort = "5925"; # "kycl"
|
2022-04-21 16:36:04 +02:00
|
|
|
|
|
|
|
settings = {
|
|
|
|
hostname = "auth.tvl.fyi";
|
|
|
|
http-relative-path = "/auth";
|
|
|
|
proxy = "edge";
|
|
|
|
};
|
2021-12-25 15:06:15 +01:00
|
|
|
|
|
|
|
database = {
|
|
|
|
type = "postgresql";
|
2022-05-22 23:51:49 +02:00
|
|
|
passwordFile = config.age.secretsDir + "/keycloak-db";
|
2021-12-25 15:06:15 +01:00
|
|
|
createLocally = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Allow Keycloak access to the LDAP module by forcing in the JVM
|
|
|
|
# configuration
|
|
|
|
systemd.services.keycloak.environment.PREPEND_JAVA_OPTS =
|
|
|
|
"--add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED";
|
|
|
|
|
2020-07-02 23:53:59 +02:00
|
|
|
security.sudo.extraRules = [
|
|
|
|
{
|
2022-01-30 17:06:58 +01:00
|
|
|
groups = [ "wheel" ];
|
|
|
|
commands = [{ command = "ALL"; options = [ "NOPASSWD" ]; }];
|
2020-07-02 23:53:59 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-07-02 20:19:08 +02:00
|
|
|
users = {
|
|
|
|
# Set up a user & group for git shenanigans
|
2022-01-30 17:06:58 +01:00
|
|
|
groups.git = { };
|
2020-07-02 20:19:08 +02:00
|
|
|
users.git = {
|
|
|
|
group = "git";
|
2021-04-13 12:21:42 +02:00
|
|
|
isSystemUser = true;
|
2020-07-12 15:44:24 +02:00
|
|
|
createHome = true;
|
|
|
|
home = "/var/lib/git";
|
2020-07-02 20:19:08 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
system.stateVersion = "20.03";
|
2021-04-12 17:59:51 +02:00
|
|
|
}
|