2024-04-22 18:35:50 +00:00
|
|
|
{
|
|
|
|
lib,
|
2024-07-11 15:50:43 +00:00
|
|
|
modulesPath,
|
2024-05-02 23:43:48 +00:00
|
|
|
pkgs,
|
2024-04-22 18:35:50 +00:00
|
|
|
...
|
2024-08-25 15:02:35 +00:00
|
|
|
}:
|
|
|
|
{
|
2024-04-22 18:35:50 +00:00
|
|
|
imports = [
|
|
|
|
"${modulesPath}/virtualisation/amazon-image.nix"
|
|
|
|
./anti-feature.nix
|
2024-08-11 10:13:36 +00:00
|
|
|
|
|
|
|
./services/forgejo.nix
|
|
|
|
./services/hysteria.nix
|
|
|
|
./services/keycloak.nix
|
|
|
|
./services/miniflux.nix
|
|
|
|
./services/murmur.nix
|
|
|
|
./services/ntfy.nix
|
|
|
|
./services/pixivfe.nix
|
|
|
|
./services/searx.nix
|
2024-08-12 13:23:46 +00:00
|
|
|
./services/vaultwarden.nix
|
2024-04-22 18:35:50 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
boot.loader.grub.device = lib.mkForce "/dev/nvme0n1";
|
2024-08-12 07:25:36 +00:00
|
|
|
system.stateVersion = "24.05";
|
2024-04-22 21:01:38 +00:00
|
|
|
|
2024-05-23 16:15:10 +00:00
|
|
|
swapDevices = [
|
|
|
|
{
|
|
|
|
device = "/var/lib/swapfile";
|
|
|
|
size = 4 * 1024; # 4 GiB
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
# WORKAROUND:
|
|
|
|
systemd.services."print-host-key".enable = false;
|
|
|
|
|
|
|
|
### Secrets
|
2024-08-25 15:02:35 +00:00
|
|
|
sops.secrets = lib.mapAttrs (_name: value: value // { sopsFile = ./secrets.yaml; }) {
|
2024-07-21 10:09:21 +00:00
|
|
|
"hysteria/auth" = {
|
2024-08-25 15:02:35 +00:00
|
|
|
restartUnits = [ "hysteria.service" ];
|
2024-07-21 10:09:21 +00:00
|
|
|
};
|
|
|
|
"pixivfe/environment" = {
|
2024-08-25 15:02:35 +00:00
|
|
|
restartUnits = [ "pixivfe.service" ];
|
2024-07-21 10:09:21 +00:00
|
|
|
};
|
|
|
|
"searx/environment" = {
|
2024-08-25 15:02:35 +00:00
|
|
|
restartUnits = [ "searx.service" ];
|
2024-07-21 10:09:21 +00:00
|
|
|
};
|
|
|
|
"miniflux/environment" = {
|
2024-08-25 15:02:35 +00:00
|
|
|
restartUnits = [ "miniflux.service" ];
|
2024-05-23 16:15:10 +00:00
|
|
|
};
|
2024-08-12 13:23:46 +00:00
|
|
|
"vaultwarden/environment" = {
|
2024-08-25 15:02:35 +00:00
|
|
|
restartUnits = [ "vaultwarden.service" ];
|
2024-08-12 13:23:46 +00:00
|
|
|
};
|
2024-05-23 16:15:10 +00:00
|
|
|
};
|
2024-04-22 21:01:38 +00:00
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
### Services
|
2024-08-25 15:02:35 +00:00
|
|
|
networking.firewall.allowedUDPPorts = [ 443 ]; # hysteria
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
80
|
|
|
|
443
|
|
|
|
]; # caddy
|
2024-05-02 23:43:48 +00:00
|
|
|
|
2024-05-04 08:12:36 +00:00
|
|
|
systemd.tmpfiles.settings = {
|
|
|
|
"10-www" = {
|
|
|
|
"/var/www/robots/robots.txt".C.argument = toString ./robots.txt;
|
2024-05-23 16:15:10 +00:00
|
|
|
"/var/www/matrix/client".C.argument = toString ./matrix-client.json;
|
|
|
|
"/var/www/matrix/server".C.argument = toString ./matrix-server.json;
|
2024-05-04 08:12:36 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
2024-08-19 14:45:31 +00:00
|
|
|
configFile = pkgs.replaceVars ./Caddyfile {
|
2024-05-23 16:15:10 +00:00
|
|
|
"element" = pkgs.element-web.override {
|
2024-06-17 03:33:36 +00:00
|
|
|
conf.default_server_config."m.homeserver" = {
|
2024-05-23 16:15:10 +00:00
|
|
|
base_url = "https://matrix.ny4.dev";
|
2024-06-17 03:33:36 +00:00
|
|
|
server_name = "ny4.dev";
|
2024-05-23 16:15:10 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-31 13:34:24 +00:00
|
|
|
"cinny" = pkgs.cinny.override {
|
|
|
|
conf = {
|
|
|
|
defaultHomeserver = 0;
|
2024-08-25 15:02:35 +00:00
|
|
|
homeserverList = [ "ny4.dev" ];
|
2024-07-31 13:34:24 +00:00
|
|
|
};
|
|
|
|
};
|
2024-05-23 16:15:10 +00:00
|
|
|
};
|
2024-05-02 23:43:48 +00:00
|
|
|
};
|
2024-04-22 21:01:38 +00:00
|
|
|
|
2024-08-11 11:02:04 +00:00
|
|
|
services.postgresql = {
|
|
|
|
package = pkgs.postgresql_16;
|
|
|
|
settings = {
|
|
|
|
max_connections = 200;
|
|
|
|
shared_buffers = "256MB";
|
|
|
|
effective_cache_size = "768MB";
|
|
|
|
maintenance_work_mem = "64MB";
|
|
|
|
checkpoint_completion_target = 0.9;
|
|
|
|
wal_buffers = "7864kB";
|
|
|
|
default_statistics_target = 100;
|
|
|
|
random_page_cost = 1.1;
|
|
|
|
effective_io_concurrency = 200;
|
|
|
|
work_mem = "655kB";
|
|
|
|
huge_pages = "off";
|
|
|
|
min_wal_size = "1GB";
|
|
|
|
max_wal_size = "4GB";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
services.wastebin = {
|
|
|
|
enable = true;
|
|
|
|
settings.WASTEBIN_ADDRESS_PORT = "127.0.0.1:8200";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.uptime-kuma = {
|
|
|
|
enable = true;
|
|
|
|
settings.PORT = "8300";
|
|
|
|
};
|
|
|
|
|
2024-07-21 11:54:56 +00:00
|
|
|
services.redlib = {
|
2024-07-13 18:01:10 +00:00
|
|
|
enable = true;
|
|
|
|
address = "127.0.0.1";
|
|
|
|
port = 9400;
|
|
|
|
};
|
|
|
|
|
2024-05-02 23:43:48 +00:00
|
|
|
### Prevents me from bankrupt
|
|
|
|
# https://fmk.im/p/shutdown-aws/
|
|
|
|
services.vnstat.enable = true;
|
|
|
|
systemd.services."no-bankrupt" = {
|
|
|
|
serviceConfig.Type = "oneshot";
|
2024-08-25 15:02:35 +00:00
|
|
|
path = with pkgs; [
|
|
|
|
coreutils
|
|
|
|
gawk
|
|
|
|
vnstat
|
|
|
|
systemd
|
|
|
|
];
|
2024-05-02 23:43:48 +00:00
|
|
|
script = ''
|
|
|
|
TRAFF_TOTAL=1900
|
|
|
|
TRAFF_USED=$(vnstat --oneline b | awk -F ';' '{print $11}')
|
|
|
|
CHANGE_TO_GB=$(($TRAFF_USED / 1073741824))
|
|
|
|
|
|
|
|
if [ $CHANGE_TO_GB -gt $TRAFF_TOTAL ]; then
|
|
|
|
shutdown -h now
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
systemd.timers."no-bankrupt" = {
|
|
|
|
timerConfig.OnCalendar = "*:0:0"; # Check every hour
|
|
|
|
};
|
2024-04-22 18:35:50 +00:00
|
|
|
}
|