2023-04-03 16:50:52 +03:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
2023-04-14 14:12:45 +03:00
|
|
|
agenix,
|
|
|
|
myData,
|
2023-04-03 16:50:52 +03:00
|
|
|
...
|
2023-08-14 09:09:14 +03:00
|
|
|
}: {
|
2023-04-03 16:50:52 +03:00
|
|
|
imports = [
|
|
|
|
./hardware-configuration.nix
|
|
|
|
./zfs.nix
|
|
|
|
];
|
2023-01-03 12:31:37 +02:00
|
|
|
|
2023-04-14 14:12:45 +03:00
|
|
|
mj = {
|
|
|
|
stateVersion = "22.11";
|
|
|
|
timeZone = "UTC";
|
|
|
|
|
2023-07-18 16:32:45 +03:00
|
|
|
base = {
|
2023-07-26 13:58:42 +03:00
|
|
|
zfs.enable = true;
|
|
|
|
|
2023-07-20 15:02:38 +03:00
|
|
|
users.passwd = {
|
|
|
|
root.passwordFile = config.age.secrets.root-passwd-hash.path;
|
|
|
|
motiejus.passwordFile = config.age.secrets.motiejus-passwd-hash.path;
|
|
|
|
};
|
|
|
|
|
2023-07-18 16:32:45 +03:00
|
|
|
initrd = {
|
|
|
|
enable = true;
|
2023-07-23 15:58:54 +03:00
|
|
|
authorizedKeys =
|
|
|
|
(builtins.attrValues myData.people_pubkeys)
|
|
|
|
++ [myData.hosts."vno1-oh2.servers.jakst".publicKey];
|
2023-07-18 16:32:45 +03:00
|
|
|
hostKeys = ["/etc/secrets/initrd/ssh_host_ed25519_key"];
|
|
|
|
};
|
|
|
|
snapshot = {
|
|
|
|
enable = true;
|
|
|
|
mountpoints = ["/var/lib" "/var/log"];
|
|
|
|
};
|
2023-07-19 14:16:56 +03:00
|
|
|
|
|
|
|
zfsborg = {
|
|
|
|
enable = true;
|
2023-07-20 15:02:38 +03:00
|
|
|
passwordPath = config.age.secrets.borgbackup-password.path;
|
2023-07-19 14:16:56 +03:00
|
|
|
mountpoints = {
|
|
|
|
"/var/lib" = {
|
2023-07-26 12:59:19 +03:00
|
|
|
repo = "zh2769@zh2769.rsync.net:hel1-a.servers.jakst-var_lib";
|
2023-07-19 14:16:56 +03:00
|
|
|
paths = [
|
|
|
|
"/var/lib/.snapshot-latest/headscale"
|
|
|
|
];
|
2023-07-26 12:59:19 +03:00
|
|
|
backup_at = "*-*-* 00:05:00";
|
2023-07-19 14:16:56 +03:00
|
|
|
};
|
|
|
|
"/var/log" = {
|
2023-07-26 12:59:19 +03:00
|
|
|
repo = "zh2769@zh2769.rsync.net:hel1-a.servers.jakst-var_log";
|
2023-07-19 14:16:56 +03:00
|
|
|
paths = ["/var/log/.snapshot-latest/caddy/"];
|
|
|
|
patterns = [
|
|
|
|
"+ /var/log/.snapshot-latest/caddy/access-jakstys.lt.log-*.zst"
|
|
|
|
"- *"
|
|
|
|
];
|
2023-07-26 12:59:19 +03:00
|
|
|
backup_at = "*-*-* 00:01:00";
|
2023-07-19 14:16:56 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-07-20 06:58:47 +03:00
|
|
|
|
|
|
|
unitstatus = {
|
|
|
|
enable = true;
|
|
|
|
email = "motiejus+alerts@jakstys.lt";
|
2023-07-26 13:58:42 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services = {
|
2023-08-18 09:31:19 +03:00
|
|
|
node_exporter.enable = true;
|
2023-08-06 00:47:32 +03:00
|
|
|
|
2023-08-24 23:44:18 +03:00
|
|
|
headscale = {
|
|
|
|
enable = true;
|
|
|
|
clientOidcPath = config.age.secrets.headscale-client-oidc.path;
|
|
|
|
subnetCIDR = myData.tailscale_subnet.cidr;
|
|
|
|
};
|
|
|
|
|
2023-07-30 06:41:57 +03:00
|
|
|
deployerbot = {
|
|
|
|
follower = {
|
|
|
|
enable = true;
|
|
|
|
uidgid = myData.uidgid.updaterbot-deployee;
|
|
|
|
publicKey = myData.hosts."vno1-oh2.servers.jakst".publicKey;
|
|
|
|
};
|
|
|
|
};
|
2023-07-26 13:58:42 +03:00
|
|
|
postfix = {
|
|
|
|
enable = true;
|
|
|
|
saslPasswdPath = config.age.secrets.sasl-passwd.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
zfsunlock = {
|
|
|
|
enable = true;
|
2023-08-22 14:09:41 +03:00
|
|
|
targets."vno1-oh2.servers.jakst" = let
|
|
|
|
host = myData.hosts."vno1-oh2.servers.jakst";
|
|
|
|
in {
|
|
|
|
sshEndpoint = host.publicIP;
|
|
|
|
pingEndpoint = host.jakstIP;
|
|
|
|
remotePubkey = host.initrdPubKey;
|
2023-07-26 13:58:42 +03:00
|
|
|
pwFile = config.age.secrets.zfs-passphrase-vno1-oh2.path;
|
|
|
|
startAt = "*-*-* *:00/5:00";
|
|
|
|
};
|
2023-07-20 06:58:47 +03:00
|
|
|
};
|
2023-03-29 15:25:49 +03:00
|
|
|
};
|
2023-01-03 12:31:37 +02:00
|
|
|
};
|
|
|
|
|
2023-07-20 11:56:08 +03:00
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
nixos-option
|
|
|
|
graphicsmagick
|
|
|
|
];
|
2023-03-29 15:25:49 +03:00
|
|
|
|
2023-04-14 14:12:45 +03:00
|
|
|
services = {
|
|
|
|
tailscale.enable = true;
|
2023-03-29 15:25:49 +03:00
|
|
|
|
2023-04-14 14:12:45 +03:00
|
|
|
nsd = {
|
|
|
|
enable = true;
|
2023-07-18 12:31:48 +03:00
|
|
|
interfaces = ["0.0.0.0" "::"];
|
2023-04-14 14:12:45 +03:00
|
|
|
zones = {
|
|
|
|
"jakstys.lt.".data = myData.jakstysLTZone;
|
2023-03-29 15:25:49 +03:00
|
|
|
};
|
2023-02-25 15:55:08 +02:00
|
|
|
};
|
2023-03-29 15:25:49 +03:00
|
|
|
|
2023-01-04 10:06:52 +02:00
|
|
|
caddy = {
|
|
|
|
enable = true;
|
|
|
|
email = "motiejus+acme@jakstys.lt";
|
2023-03-26 14:13:30 +03:00
|
|
|
virtualHosts."www.jakstys.lt".extraConfig = ''
|
|
|
|
redir https://jakstys.lt
|
|
|
|
'';
|
2023-05-04 03:18:29 +03:00
|
|
|
virtualHosts."fwmine.jakstys.lt".extraConfig = ''
|
|
|
|
reverse_proxy fwmine.motiejus.jakst:8080
|
|
|
|
'';
|
2023-03-26 14:13:30 +03:00
|
|
|
virtualHosts."jakstys.lt" = {
|
2023-01-17 15:12:08 +02:00
|
|
|
logFormat = ''
|
2023-04-03 16:50:52 +03:00
|
|
|
output file ${config.services.caddy.logDir}/access-jakstys.lt.log {
|
|
|
|
roll_disabled
|
|
|
|
}
|
2023-01-17 15:12:08 +02:00
|
|
|
'';
|
|
|
|
extraConfig = ''
|
2023-04-13 11:57:42 +03:00
|
|
|
header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
|
|
|
|
|
2023-01-17 15:12:08 +02:00
|
|
|
header /_/* Cache-Control "public, max-age=31536000, immutable"
|
2023-04-13 11:57:42 +03:00
|
|
|
|
2023-01-17 15:12:08 +02:00
|
|
|
root * /var/www/jakstys.lt
|
|
|
|
file_server {
|
|
|
|
precompressed br gzip
|
|
|
|
}
|
2023-01-17 12:10:13 +02:00
|
|
|
|
2023-01-17 15:12:08 +02:00
|
|
|
@matrixMatch {
|
|
|
|
path /.well-known/matrix/client
|
|
|
|
path /.well-known/matrix/server
|
|
|
|
}
|
|
|
|
header @matrixMatch Content-Type application/json
|
|
|
|
header @matrixMatch Access-Control-Allow-Origin *
|
|
|
|
header @matrixMatch Cache-Control "public, max-age=3600, immutable"
|
2023-01-17 12:10:13 +02:00
|
|
|
|
2023-01-17 15:12:08 +02:00
|
|
|
handle /.well-known/matrix/client {
|
|
|
|
respond "{\"m.homeserver\": {\"base_url\": \"https://jakstys.lt\"}}" 200
|
|
|
|
}
|
|
|
|
handle /.well-known/matrix/server {
|
|
|
|
respond "{\"m.server\": \"jakstys.lt:443\"}" 200
|
|
|
|
}
|
2023-01-17 12:10:13 +02:00
|
|
|
|
2023-01-17 15:12:08 +02:00
|
|
|
handle /_matrix/* {
|
2023-03-04 10:10:31 +02:00
|
|
|
encode gzip
|
2023-08-25 16:16:28 +03:00
|
|
|
reverse_proxy http://${myData.hosts."vno1-oh2.servers.jakst".jakstIP}:${toString myData.ports.matrix-synapse}
|
2023-01-17 15:12:08 +02:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-01-03 18:39:41 +02:00
|
|
|
};
|
2023-01-17 14:07:05 +02:00
|
|
|
|
|
|
|
logrotate = {
|
|
|
|
settings = {
|
2023-03-26 14:13:30 +03:00
|
|
|
"/var/log/caddy/access-jakstys.lt.log" = {
|
2023-08-25 11:32:16 +03:00
|
|
|
rotate = -1;
|
2023-01-17 14:07:05 +02:00
|
|
|
frequency = "daily";
|
|
|
|
dateext = true;
|
|
|
|
dateyesterday = true;
|
|
|
|
compress = true;
|
|
|
|
compresscmd = "${pkgs.zstd}/bin/zstd";
|
|
|
|
compressext = ".zst";
|
|
|
|
compressoptions = "--long -19";
|
|
|
|
uncompresscmd = "${pkgs.zstd}/bin/unzstd";
|
2023-01-17 15:12:08 +02:00
|
|
|
postrotate = "${pkgs.systemd}/bin/systemctl restart caddy";
|
2023-01-17 14:07:05 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-01-03 12:31:37 +02:00
|
|
|
};
|
|
|
|
|
2023-01-04 10:06:52 +02:00
|
|
|
networking = {
|
|
|
|
hostName = "hel1-a";
|
2023-07-26 11:36:54 +03:00
|
|
|
domain = "servers.jakst";
|
2023-08-14 09:09:14 +03:00
|
|
|
firewall = {
|
2023-03-01 15:05:58 +02:00
|
|
|
allowedTCPPorts = [
|
2023-03-21 15:01:06 +02:00
|
|
|
53
|
2023-04-03 16:50:52 +03:00
|
|
|
80
|
|
|
|
443
|
2023-03-01 15:05:58 +02:00
|
|
|
];
|
2023-03-26 15:40:36 +03:00
|
|
|
allowedUDPPorts = [
|
2023-04-03 16:50:52 +03:00
|
|
|
53
|
|
|
|
443
|
2023-04-05 08:32:26 +03:00
|
|
|
41641 # tailscale
|
2023-03-26 15:40:36 +03:00
|
|
|
];
|
2023-03-29 22:21:16 +03:00
|
|
|
checkReversePath = "loose"; # for tailscale
|
2023-01-04 10:06:52 +02:00
|
|
|
};
|
2023-01-03 12:31:37 +02:00
|
|
|
};
|
|
|
|
}
|