tlaternet-server/configuration/default.nix

190 lines
4.5 KiB
Nix
Raw Normal View History

{
2022-10-29 00:13:44 +01:00
config,
pkgs,
lib,
modulesPath,
flake-inputs,
...
}: {
imports = [
flake-inputs.sops-nix.nixosModules.sops
flake-inputs.tlaternet-webserver.nixosModules.default
"${modulesPath}/profiles/headless.nix"
2022-10-30 17:43:52 +00:00
"${modulesPath}/profiles/minimal.nix"
(import ../modules)
./services/backups.nix
2022-10-21 20:48:14 +01:00
./services/conduit.nix
./services/fail2ban.nix
2023-04-23 15:46:38 +01:00
./services/foundryvtt.nix
./services/gitea.nix
./services/metrics
./services/nextcloud.nix
./services/webserver.nix
2023-04-23 15:46:38 +01:00
./services/wireguard.nix
2022-04-23 04:08:45 +01:00
./services/starbound.nix
./services/postgres.nix
./sops.nix
];
nixpkgs.overlays = [
(final: prev: {
local = import ../pkgs {
pkgs = prev;
2022-10-17 11:00:02 +01:00
lib = prev.lib;
};
})
];
nix = {
package = pkgs.nixFlakes;
extraOptions = ''
experimental-features = nix-command flakes
'';
# Enable remote builds from tlater
settings.trusted-users = ["@wheel"];
};
2022-04-23 04:08:45 +01:00
nixpkgs.config.allowUnfreePredicate = pkg:
builtins.elem (lib.getName pkg) ["steam-original" "steam-runtime" "steam-run" "steamcmd"];
2022-04-23 04:08:45 +01:00
# Optimization for minecraft servers, see:
# https://bugs.mojang.com/browse/MC-183518
boot.kernelParams = ["highres=off" "nohz=off"];
networking = {
hostName = "tlaternet";
usePredictableInterfaceNames = false;
useDHCP = false;
2022-10-29 00:13:44 +01:00
firewall = {
allowedTCPPorts = [
# http
80
443
# ssh
2222
# matrix
8448
# starbound
21025
# Minecraft
25565
2022-10-29 00:13:44 +01:00
config.services.coturn.listening-port
config.services.coturn.tls-listening-port
config.services.coturn.alt-listening-port
config.services.coturn.alt-tls-listening-port
2022-10-29 00:13:44 +01:00
];
allowedUDPPorts = [
# More minecraft
25565
2022-10-29 00:13:44 +01:00
config.services.coturn.listening-port
config.services.coturn.tls-listening-port
config.services.coturn.alt-listening-port
config.services.coturn.alt-tls-listening-port
2022-10-29 00:13:44 +01:00
];
allowedUDPPortRanges = [
{
from = config.services.coturn.min-port;
to = config.services.coturn.max-port;
}
];
};
};
2023-04-23 15:46:38 +01:00
systemd.network.enable = true;
time.timeZone = "Europe/London";
users.users.tlater = {
isNormalUser = true;
extraGroups = ["wheel"];
openssh.authorizedKeys.keyFiles = [../keys/tlater.pub];
};
services.openssh = {
enable = true;
allowSFTP = false;
ports = [2222];
startWhenNeeded = true;
2023-07-28 10:23:56 +01:00
settings = {
GatewayPorts = "yes";
PermitRootLogin = "no";
PasswordAuthentication = false;
};
};
security = {
sudo.execWheelOnly = true;
pam = {
enableSSHAgentAuth = true;
services.sudo.sshAgentAuth = true;
};
};
services.nginx = {
enable = true;
recommendedTlsSettings = true;
recommendedOptimisation = true;
recommendedGzipSettings = true;
recommendedProxySettings = true;
clientMaxBodySize = "10G";
domain = "tlater.net";
statusPage = true; # For metrics, should be accessible only from localhost
commonHttpConfig = ''
log_format upstream_time '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'rt=$request_time uct="$upstream_connect_time" '
'uht="$upstream_header_time" urt="$upstream_response_time"';
'';
};
services.logrotate = {
2022-10-14 01:11:15 +01:00
enable = true;
settings =
{
# Override the default, just keep fewer logs
nginx.rotate = 6;
}
// lib.mapAttrs' (virtualHost: _:
lib.nameValuePair "/var/log/nginx/${virtualHost}/access.log" {
frequency = "daily";
rotate = 2;
compress = true;
delaycompress = true;
su = "${config.services.nginx.user} ${config.services.nginx.group}";
postrotate = "[ ! -f /var/run/nginx/nginx.pid ] || kill -USR1 `cat /var/run/nginx/nginx.pid`";
})
config.services.nginx.virtualHosts;
};
systemd.tmpfiles.rules =
lib.mapAttrsToList (
virtualHost: _:
#
"d /var/log/nginx/${virtualHost} 0750 ${config.services.nginx.user} ${config.services.nginx.group}"
)
config.services.nginx.virtualHosts;
security.acme = {
defaults.email = "tm@tlater.net";
acceptTerms = true;
2022-10-14 01:11:15 +01:00
};
2022-10-30 17:43:52 +00:00
# Remove some unneeded packages
environment.defaultPackages = [];
system.stateVersion = "20.09";
}