added minecraft server. Backup solution is a bit ugly ATM.

This commit is contained in:
Gabe Venberg 2025-04-11 23:38:32 +02:00
parent 39bee826c3
commit 10289cb930
8 changed files with 94 additions and 9 deletions

View file

@ -6,10 +6,10 @@
}: {
programs.yazi.enable = true;
# optional dependencies for yazi.
programs={
fzf.enable=true;
ripgrep.enable=true;
zoxide.enable=true;
programs = {
fzf.enable = true;
ripgrep.enable = true;
zoxide.enable = true;
};
home.packages = with pkgs; [
ffmpeg

View file

@ -5,6 +5,9 @@
lib,
...
}: {
virtualisation.docker.enable = true;
virtualisation.docker = {
enable = true;
autoPrune.enable = true;
};
users.users.${config.host.user}.extraGroups = ["docker"];
}

View file

@ -13,7 +13,6 @@
hostname = "factorio";
ports = [
"34197:34197/udp"
"27015:27015/tcp"
];
environment = {UPDATE_MODS_ON_START = "true";};
};

View file

@ -0,0 +1,48 @@
{
inputs,
config,
pkgs,
lib,
...
}: {
virtualisation.oci-containers = {
backend = "docker";
containers.minecraft = {
image = "itzg/minecraft-server";
volumes = ["/storage/minecraft:/data"];
hostname = "minecraft";
ports = [
"25565:25565"
];
environment = {
EULA = "TRUE";
TYPE = "FORGE";
VERSION = "1.20.1";
PACKWIZ_URL = "https://static.venberg.xyz/minecraft/less-than-compact-2/pack.toml";
MEMORY = "16G";
USE_AIKAR_FLAGS = "true";
UID = "1000";
GID = "100";
STOP_SERVER_ANNOUNCE_DELAY = "30";
ENABLE_ROLLING_LOGS = "true";
GUI = "FALSE";
# SETUP_ONLY = "true";
MOTD = "Welcome!";
DIFFICULTY = "normal";
OPS = ''
TheToric
'';
ENFORCE_WHITELIST = "true";
ENABLE_WHITELIST = "true";
ANNOUNCE_PLAYER_ACHIEVEMENTS = "true";
ALLOW_FLIGHT = "TRUE";
ENABLE_AUTOPAUSE = "true";
MAX_TICK_TIME = "-1";
};
extraOptions = ["--stop-timeout=60"];
};
};
imports = [
./docker.nix
];
}

View file

@ -25,7 +25,7 @@ in {
];
};
};
services.nginx.virtualHosts."static.venberg.xyz" = {
services.nginx.virtualHosts."directory.venberg.xyz" = {
enableACME = true;
forceSSL = true;
locations."/" = {

View file

@ -0,0 +1,13 @@
{
inputs,
config,
pkgs,
lib,
...
}: {
services.nginx.virtualHosts."static.venberg.xyz" = {
enableACME = true;
forceSSL = true;
root = "/storage/static";
};
}

View file

@ -24,7 +24,9 @@ inputs.nixpkgs.lib.nixosSystem {
../../configs/nixos/grocy.nix
../../configs/nixos/factorio-docker.nix
../../configs/nixos/cyberchef.nix
../../configs/nixos/miniserve-static.nix
../../configs/nixos/miniserve-directory.nix
../../configs/nixos/minecraft-docker.nix
../../configs/nixos/nginx-static.nix
({
config,
pkgs,

View file

@ -6,6 +6,23 @@
...
}: let
port = "8090";
# TODO: I should really make restic a custom module at this point, with an enable option, a option for being the host,
# and the ability to add paths and pre/post commands from multiple places.
preBackup = pkgs.writeShellScriptBin "mc-docker-pre-backup" ''
set -euxo pipefail
docker exec minecraft rcon-cli "say server backing up, expect minor lag"
sleep 10
docker exec minecraft rcon-cli "save-all flush"
docker exec minecraft rcon-cli "save-off"
sleep 10
'';
postBackup = pkgs.writeShellScriptBin "mc-docker-post-backup" ''
set -euxo pipefail
docker exec minecraft rcon-cli "save-on"
docker exec minecraft rcon-cli "say server backup succsessful!"
'';
in {
services.restic.server = lib.mkIf (inputs ? nix-secrets) {
enable = true;
@ -46,11 +63,14 @@ in {
repositoryFile = "/backup/restic/";
passwordFile = config.sops.secrets.restic-password.path;
initialize = true;
backupPrepareCommand = "${preBackup}/bin/mc-docker-pre-backup";
backupCleanupCommand = "${postBackup}/bin/mc-docker-post-backup";
paths = [
"/storage/syncthing"
"/storage/factorio"
"/storage/minecraft"
];
pruneOpts=[
pruneOpts = [
"--keep-within 14d"
"--keep-daily 14"
"--keep-weekly 8"