2021-04-12 01:35:24 +01:00
|
|
|
{
|
2022-10-29 00:13:44 +01:00
|
|
|
config,
|
2022-10-10 13:03:08 +01:00
|
|
|
pkgs,
|
|
|
|
lib,
|
2022-10-13 00:03:32 +01:00
|
|
|
modulesPath,
|
2023-02-26 05:44:54 +00:00
|
|
|
flake-inputs,
|
2022-10-10 13:03:08 +01:00
|
|
|
...
|
|
|
|
}: {
|
2021-04-19 00:39:33 +01:00
|
|
|
imports = [
|
2024-03-02 01:27:24 +00:00
|
|
|
flake-inputs.disko.nixosModules.disko
|
2023-02-26 05:44:54 +00:00
|
|
|
flake-inputs.sops-nix.nixosModules.sops
|
|
|
|
flake-inputs.tlaternet-webserver.nixosModules.default
|
|
|
|
|
2022-10-13 00:03:32 +01:00
|
|
|
"${modulesPath}/profiles/headless.nix"
|
2022-10-30 17:43:52 +00:00
|
|
|
"${modulesPath}/profiles/minimal.nix"
|
2022-10-13 00:03:32 +01:00
|
|
|
(import ../modules)
|
|
|
|
|
2023-09-22 05:20:36 +01:00
|
|
|
./services/backups.nix
|
2022-10-21 20:48:14 +01:00
|
|
|
./services/conduit.nix
|
2023-10-07 21:14:43 +01:00
|
|
|
./services/fail2ban.nix
|
2023-04-23 15:46:38 +01:00
|
|
|
./services/foundryvtt.nix
|
2021-04-19 00:39:33 +01:00
|
|
|
./services/gitea.nix
|
2023-10-07 21:14:43 +01:00
|
|
|
./services/metrics
|
2021-04-19 00:39:33 +01:00
|
|
|
./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
|
2022-10-12 18:04:06 +01:00
|
|
|
./services/postgres.nix
|
2022-10-12 02:03:22 +01:00
|
|
|
./sops.nix
|
2021-04-19 00:39:33 +01:00
|
|
|
];
|
2021-04-12 01:35:24 +01:00
|
|
|
|
2022-10-13 00:03:32 +01:00
|
|
|
nixpkgs.overlays = [
|
|
|
|
(final: prev: {
|
|
|
|
local = import ../pkgs {
|
|
|
|
pkgs = prev;
|
2022-10-17 11:00:02 +01:00
|
|
|
lib = prev.lib;
|
2022-10-13 00:03:32 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2021-04-12 01:35:24 +01:00
|
|
|
nix = {
|
|
|
|
package = pkgs.nixFlakes;
|
|
|
|
extraOptions = ''
|
|
|
|
experimental-features = nix-command flakes
|
|
|
|
'';
|
2021-04-28 00:22:21 +01:00
|
|
|
|
|
|
|
# Enable remote builds from tlater
|
2023-01-11 02:00:33 +00:00
|
|
|
settings.trusted-users = ["@wheel"];
|
2021-04-12 01:35:24 +01:00
|
|
|
};
|
|
|
|
|
2022-04-23 04:08:45 +01:00
|
|
|
nixpkgs.config.allowUnfreePredicate = pkg:
|
2023-01-11 02:00:33 +00:00
|
|
|
builtins.elem (lib.getName pkg) ["steam-original" "steam-runtime" "steam-run" "steamcmd"];
|
2022-04-23 04:08:45 +01:00
|
|
|
|
2022-10-12 01:24:54 +01:00
|
|
|
# Optimization for minecraft servers, see:
|
|
|
|
# https://bugs.mojang.com/browse/MC-183518
|
2022-10-10 13:03:08 +01:00
|
|
|
boot.kernelParams = ["highres=off" "nohz=off"];
|
2021-08-25 19:45:15 +01:00
|
|
|
|
2021-04-12 01:35:24 +01:00
|
|
|
networking = {
|
|
|
|
usePredictableInterfaceNames = false;
|
|
|
|
useDHCP = false;
|
|
|
|
|
2022-10-29 00:13:44 +01:00
|
|
|
firewall = {
|
|
|
|
allowedTCPPorts = [
|
|
|
|
# http
|
|
|
|
80
|
|
|
|
443
|
|
|
|
# ssh
|
|
|
|
2222
|
|
|
|
# matrix
|
|
|
|
8448
|
|
|
|
# starbound
|
|
|
|
21025
|
2023-01-11 02:00:13 +00:00
|
|
|
# Minecraft
|
|
|
|
25565
|
2022-10-29 00:13:44 +01:00
|
|
|
|
|
|
|
config.services.coturn.listening-port
|
|
|
|
config.services.coturn.tls-listening-port
|
2022-11-05 22:26:52 +00:00
|
|
|
config.services.coturn.alt-listening-port
|
|
|
|
config.services.coturn.alt-tls-listening-port
|
2022-10-29 00:13:44 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
allowedUDPPorts = [
|
2023-01-11 02:00:13 +00:00
|
|
|
# More minecraft
|
|
|
|
25565
|
|
|
|
|
2022-10-29 00:13:44 +01:00
|
|
|
config.services.coturn.listening-port
|
|
|
|
config.services.coturn.tls-listening-port
|
2022-11-05 22:26:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2021-04-12 01:35:24 +01:00
|
|
|
};
|
|
|
|
|
2023-04-23 15:46:38 +01:00
|
|
|
systemd.network.enable = true;
|
|
|
|
|
2021-04-12 01:35:24 +01:00
|
|
|
time.timeZone = "Europe/London";
|
|
|
|
|
|
|
|
users.users.tlater = {
|
|
|
|
isNormalUser = true;
|
2022-10-10 13:03:08 +01:00
|
|
|
extraGroups = ["wheel"];
|
|
|
|
openssh.authorizedKeys.keyFiles = [../keys/tlater.pub];
|
2021-04-12 01:35:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.openssh = {
|
|
|
|
enable = true;
|
|
|
|
allowSFTP = false;
|
2022-10-10 13:03:08 +01:00
|
|
|
ports = [2222];
|
2021-04-12 01:35:24 +01:00
|
|
|
startWhenNeeded = true;
|
2023-07-28 10:23:56 +01:00
|
|
|
|
|
|
|
settings = {
|
|
|
|
GatewayPorts = "yes";
|
|
|
|
PermitRootLogin = "no";
|
|
|
|
PasswordAuthentication = false;
|
|
|
|
};
|
2021-04-12 01:35:24 +01:00
|
|
|
};
|
|
|
|
|
2022-11-05 17:59:27 +00:00
|
|
|
security = {
|
|
|
|
sudo.execWheelOnly = true;
|
|
|
|
|
|
|
|
pam = {
|
|
|
|
enableSSHAgentAuth = true;
|
|
|
|
services.sudo.sshAgentAuth = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-04-12 01:35:24 +01:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
clientMaxBodySize = "10G";
|
|
|
|
|
2023-10-07 21:14:43 +01:00
|
|
|
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"';
|
|
|
|
'';
|
2021-04-12 01:35:24 +01:00
|
|
|
};
|
|
|
|
|
2023-10-07 21:14:43 +01:00
|
|
|
services.logrotate = {
|
2022-10-14 01:11:15 +01:00
|
|
|
enable = true;
|
|
|
|
|
2023-10-13 09:16:10 +01:00
|
|
|
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;
|
2023-10-07 21:14:43 +01:00
|
|
|
};
|
|
|
|
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 = [];
|
|
|
|
|
2021-04-12 01:35:24 +01:00
|
|
|
system.stateVersion = "20.09";
|
|
|
|
}
|