Files
nixos-config/nixos-configurations/server/default.nix

293 lines
9.3 KiB
Nix
Raw Normal View History

2023-11-01 16:59:14 +01:00
{ inputs, pkgs, config, lib, ... }:
2023-07-02 00:18:17 +02:00
{
imports = [
2023-10-31 12:10:31 +01:00
inputs.agenix.nixosModules.default
2023-07-02 00:18:17 +02:00
./hardware-configuration.nix
../shared.nix
];
2023-08-04 09:32:11 +00:00
nix.settings.trusted-users = [ "thiloho" ];
age.secrets = {
2024-01-04 14:07:22 +01:00
hedgedoc-environment-file.file =
../../secrets/hedgedoc-environment-file.age;
discord-bot-token.file = ../../secrets/discord-bot-token.age;
todos-environment-file.file = ../../secrets/todos-environment-file.age;
2024-01-04 14:07:22 +01:00
"restic/minecraft-environment-file".file =
../../secrets/restic/minecraft-environment-file.age;
"restic/minecraft-repository".file =
../../secrets/restic/minecraft-repository.age;
"restic/minecraft-password".file =
../../secrets/restic/minecraft-password.age;
"restic/hedgedoc-environment-file".file =
../../secrets/restic/hedgedoc-environment-file.age;
"restic/hedgedoc-repository".file =
../../secrets/restic/hedgedoc-repository.age;
"restic/hedgedoc-password".file =
../../secrets/restic/hedgedoc-password.age;
"restic/todos-environment-file".file =
../../secrets/restic/todos-environment-file.age;
2023-12-22 09:57:07 +01:00
"restic/todos-repository".file = ../../secrets/restic/todos-repository.age;
"restic/todos-password".file = ../../secrets/restic/todos-password.age;
2024-01-04 14:07:22 +01:00
"restic/discord-bot-environment-file".file =
../../secrets/restic/discord-bot-environment-file.age;
"restic/discord-bot-repository".file =
../../secrets/restic/discord-bot-repository.age;
"restic/discord-bot-password".file =
../../secrets/restic/discord-bot-password.age;
};
2023-11-01 00:09:25 +01:00
2024-01-04 14:07:22 +01:00
environment.systemPackages = with pkgs; [ nodejs_20 ];
2023-07-29 22:59:36 +02:00
networking = {
2023-07-29 23:01:20 +02:00
hostName = "server";
2023-07-29 22:59:36 +02:00
firewall = {
2024-01-14 13:44:29 +01:00
allowedTCPPorts = [ 80 443 25565 3232 ];
allowedUDPPorts = [ 80 443 25565 3232 ];
2023-07-29 22:59:36 +02:00
};
};
2023-07-24 15:17:18 +02:00
2023-07-29 22:33:53 +02:00
services = {
2023-08-04 20:44:41 +02:00
openssh = {
enable = true;
settings.PasswordAuthentication = false;
};
minecraft-server = {
2023-07-29 22:33:53 +02:00
enable = true;
eula = true;
declarative = true;
2023-10-03 16:09:14 +02:00
openFirewall = true;
whitelist = {
thilo_ho = "4e4d744d-7748-46bc-add8-b3e8ca3b4cf5";
2024-01-19 22:41:15 +01:00
Liaxswan = "ccbf3468-a6b4-4d7b-9837-5a2451deca79";
};
serverProperties = {
difficulty = 3;
max-players = 10;
motd = "Thilo's SMP";
};
2023-10-03 16:09:14 +02:00
};
2023-07-29 22:33:53 +02:00
nginx = {
enable = true;
2023-09-26 20:35:05 +02:00
recommendedProxySettings = true;
recommendedTlsSettings = true;
2023-07-29 22:33:53 +02:00
virtualHosts = {
"thilohohlt.com" = {
2023-07-29 23:19:54 +02:00
enableACME = true;
forceSSL = true;
2023-07-29 22:33:53 +02:00
root = inputs.website;
};
2023-08-01 21:58:41 +00:00
"aurora.thilohohlt.com" = {
enableACME = true;
forceSSL = true;
2023-08-01 23:28:39 +00:00
root = inputs.aurora-blog-template.packages.${pkgs.system}.default;
2023-08-01 21:58:41 +00:00
};
2023-09-26 20:35:05 +02:00
"collab.thilohohlt.com" = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://localhost:3300";
locations."/socket.io/" = {
proxyPass = "http://localhost:3300";
proxyWebsockets = true;
extraConfig = "proxy_ssl_server_name on;";
};
};
2023-11-12 19:18:41 +01:00
"todos.thilohohlt.com" = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://localhost:5173";
};
2023-11-22 18:26:17 +01:00
"git.thilohohlt.com" = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://localhost:3001";
};
2023-08-04 20:44:41 +02:00
};
};
2023-09-25 15:50:20 +02:00
hedgedoc = {
enable = true;
settings = {
port = 3300;
domain = "collab.thilohohlt.com";
db = {
dialect = "postgres";
host = "/run/postgresql";
database = "hedgedoc";
};
2023-09-26 20:35:05 +02:00
protocolUseSSL = true;
allowAnonymous = false;
allowEmailRegister = false;
email = false;
2023-09-25 15:50:20 +02:00
};
2023-11-01 00:09:25 +01:00
environmentFile = config.age.secrets.hedgedoc-environment-file.path;
2023-09-25 15:50:20 +02:00
};
2023-11-22 18:26:17 +01:00
gitea = {
enable = true;
appName = "Gitea instance of Thilo";
database = {
type = "postgres";
host = "/run/postgresql";
};
settings.service.DISABLE_REGISTRATION = true;
settings.server = {
DOMAIN = "thilohohlt.com";
ROOT_URL = "https://git.thilohohlt.com";
HTTP_PORT = 3001;
};
};
2024-01-14 13:44:29 +01:00
invidious = {
enable = true;
port = 3232;
domain = "invidious.thilohohlt.com";
nginx.enable = true;
2024-01-14 15:34:21 +01:00
settings = {
db.user = "invidious";
registration_enabled = false;
};
2024-01-14 13:44:29 +01:00
};
2023-09-25 15:50:20 +02:00
postgresql = {
enable = true;
package = pkgs.postgresql_15;
2023-11-22 18:26:17 +01:00
ensureDatabases = [ "dcbot" "hedgedoc" "todos" "gitea" ];
2023-09-26 20:35:05 +02:00
ensureUsers = [
{
name = "hedgedoc";
2023-11-26 15:56:56 +01:00
ensureDBOwnership = true;
2023-09-26 20:35:05 +02:00
}
2023-11-22 18:26:17 +01:00
{
name = "gitea";
2023-11-26 15:56:56 +01:00
ensureDBOwnership = true;
2023-11-22 18:26:17 +01:00
}
2023-09-26 20:35:05 +02:00
];
2023-11-01 16:59:14 +01:00
authentication = lib.mkForce ''
2023-09-25 15:50:20 +02:00
#type database DBuser auth-method
local all all trust
'';
};
restic.backups = {
minecraft-backup = {
initialize = true;
2024-01-04 14:07:22 +01:00
environmentFile =
config.age.secrets."restic/minecraft-environment-file".path;
repositoryFile = config.age.secrets."restic/minecraft-repository".path;
2023-12-22 09:57:07 +01:00
passwordFile = config.age.secrets."restic/minecraft-password".path;
2024-01-04 14:07:22 +01:00
paths = [ "/var/lib/minecraft/world" ];
2024-01-04 14:07:22 +01:00
pruneOpts = [ "--keep-daily 7" "--keep-weekly 5" "--keep-monthly 12" ];
2023-12-22 09:57:07 +01:00
};
hedgedoc-database-backup = {
initialize = true;
2024-01-04 14:07:22 +01:00
environmentFile =
config.age.secrets."restic/hedgedoc-environment-file".path;
2023-12-22 09:57:07 +01:00
repositoryFile = config.age.secrets."restic/hedgedoc-repository".path;
passwordFile = config.age.secrets."restic/hedgedoc-password".path;
2024-01-04 14:07:22 +01:00
paths =
[ "/var/lib/hedgedoc/uploads" "/var/lib/hedgedoc/hedgedoc.dump" ];
2023-12-22 09:57:07 +01:00
backupPrepareCommand = ''
${config.services.postgresql.package}/bin/pg_dump -U postgres -Fc hedgedoc > /var/lib/hedgedoc/hedgedoc.dump
'';
2024-01-04 14:07:22 +01:00
pruneOpts = [ "--keep-daily 7" "--keep-weekly 5" "--keep-monthly 12" ];
2023-12-22 09:57:07 +01:00
};
todos-database-backup = {
initialize = true;
2024-01-04 14:07:22 +01:00
environmentFile =
config.age.secrets."restic/todos-environment-file".path;
2023-12-22 09:57:07 +01:00
repositoryFile = config.age.secrets."restic/todos-repository".path;
passwordFile = config.age.secrets."restic/todos-password".path;
paths = [ "/var/lib/todos.dump" ];
backupPrepareCommand = ''
2023-12-22 10:15:21 +01:00
${config.services.postgresql.package}/bin/pg_dump -U postgres -Fc todos > /var/lib/todos.dump
2023-12-22 09:57:07 +01:00
'';
2024-01-04 14:07:22 +01:00
pruneOpts = [ "--keep-daily 7" "--keep-weekly 5" "--keep-monthly 12" ];
2023-12-22 09:57:07 +01:00
};
discord-bot-database-backup = {
initialize = true;
2024-01-04 14:07:22 +01:00
environmentFile =
config.age.secrets."restic/discord-bot-environment-file".path;
repositoryFile =
config.age.secrets."restic/discord-bot-repository".path;
2023-12-22 09:57:07 +01:00
passwordFile = config.age.secrets."restic/discord-bot-password".path;
paths = [ "/var/lib/dcbot.dump" ];
backupPrepareCommand = ''
2023-12-22 10:15:21 +01:00
${config.services.postgresql.package}/bin/pg_dump -U postgres -Fc dcbot > /var/lib/dcbot.dump
2023-12-22 09:57:07 +01:00
'';
2024-01-04 14:07:22 +01:00
pruneOpts = [ "--keep-daily 7" "--keep-weekly 5" "--keep-monthly 12" ];
};
};
2023-07-24 14:38:54 +02:00
};
2023-08-04 20:44:41 +02:00
security = {
acme = {
acceptTerms = true;
defaults.email = "thilo.hohlt@tutanota.com";
};
2023-07-29 23:19:54 +02:00
};
2023-11-12 19:18:41 +01:00
systemd.services = {
todoapp = {
description = "Todo application to plan your daily tasks effectively";
2024-01-04 14:07:22 +01:00
wantedBy = [ "multi-user.target" ];
2023-11-12 19:18:41 +01:00
serviceConfig = {
Type = "simple";
2024-01-04 14:07:22 +01:00
Environment =
"PORT=5173 DOTENV_CONFIG_PATH=${config.age.secrets.todos-environment-file.path}";
2023-11-12 19:18:41 +01:00
ExecStart = "${pkgs.nodejs_20}/bin/node -r dotenv/config .";
WorkingDirectory = inputs.todos.packages.${pkgs.system}.default;
Restart = "always";
};
};
todoapp-check-due-dates = {
2024-01-04 14:07:22 +01:00
description =
"Set is_overdue for todo in database to true if todo is overdue";
wantedBy = [ "timers.target" ];
path = [ pkgs.postgresql_15 ];
script = ''
2024-01-04 16:26:33 +01:00
psql -d todos -c "UPDATE user_todo SET is_overdue = true WHERE DATE_TRUNC('day', NOW() AT TIME ZONE 'CET') > due_date AND is_completed = false AND is_overdue = false"
'';
2024-01-04 14:07:22 +01:00
serviceConfig = { User = "postgres"; };
partOf = [ "todoapp.service" ];
startAt = "daily";
};
2023-11-12 19:18:41 +01:00
denbot = {
description = "Thilo's Den discord bot";
2024-01-04 14:07:22 +01:00
wantedBy = [ "multi-user.target" ];
2023-11-12 19:18:41 +01:00
serviceConfig = {
Type = "simple";
ExecStartPre = [
"${pkgs.nodejs_20}/bin/node dbInit.js"
"${pkgs.nodejs_20}/bin/node deploy-commands.js --token=${config.age.secrets.discord-bot-token.path} --clientId=1142441791459704912"
];
2024-01-04 14:07:22 +01:00
ExecStart =
"${pkgs.nodejs_20}/bin/node index.js --token=${config.age.secrets.discord-bot-token.path}";
2023-11-12 19:18:41 +01:00
WorkingDirectory = inputs.denbot.packages.${pkgs.system}.default;
Restart = "always";
};
};
};
2023-07-24 14:38:54 +02:00
users.users.thiloho.openssh.authorizedKeys.keys = [
2023-08-11 17:04:19 +02:00
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMkvr+vT7Ik0fjquxb9xQBfVVWJPgrfC+vJZsyG2V+/G thiloho@pc"
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ5jOELdhQ85uKV8l2QkbLhjdPr142p1AmPzpawaJ7ws thiloho@laptop"
2023-07-24 14:38:54 +02:00
];
2023-07-02 00:18:17 +02:00
home-manager.users.thiloho = { pkgs, lib, ... }: {
2024-01-04 14:07:22 +01:00
home = { stateVersion = "23.05"; };
2023-07-02 00:18:17 +02:00
};
system.stateVersion = "23.05";
2023-11-19 05:11:06 +01:00
}