diff --git a/common.nix b/common.nix index 094d272..22662bb 100644 --- a/common.nix +++ b/common.nix @@ -18,7 +18,7 @@ # Services # ./services/server-permissions.nix - #./services/game-servers.nix + ./services/game-servers.nix ./services/qbittorrent-nox.nix ./services/nginx.nix ./services/go2rtc.nix diff --git a/services/game-servers.nix b/services/game-servers.nix index 4e3d3f9..660c3a9 100644 --- a/services/game-servers.nix +++ b/services/game-servers.nix @@ -1,71 +1,89 @@ { config, pkgs, lib, ... }: { config = lib.mkIf (config.networking.hostName == "FredOS-Mediaserver") { - ## <----- V-RISING ----> ## virtualisation.docker.enable = true; systemd.tmpfiles.rules = [ - "d /var/lib/v-rising 0755 root root -" - "d /var/lib/v-rising/server 0755 root root -" - "d /var/lib/v-rising/persistentdata 0755 root root -" + "d /var/lib/7dtd 0755 root root -" + "d /var/lib/7dtd/saves 0755 root root -" + "d /var/lib/7dtd/serverfiles 0755 root root -" + "d /var/lib/7dtd/lgsm 0755 root root -" + "d /var/lib/7dtd/log 0755 root root -" + "d /var/lib/7dtd/backups 0755 root root -" ]; + ## <----- 7 DAYS TO DIE ----> ## virtualisation.oci-containers = { backend = "docker"; - containers.v-rising = { - image = "trueosiris/vrising:latest"; - entrypoint = "/bin/bash"; - cmd = [ "-c" "sed -i 's/\\r$//' /start.sh && /start.sh" ]; - + containers."7dtd" = { + image = "vinanrra/7dtd-server:latest"; volumes = [ - "/var/lib/v-rising/server:/mnt/vrising/server" - "/var/lib/v-rising/persistentdata:/mnt/vrising/persistentdata" + "/var/lib/7dtd/saves:/home/sdtdserver/.local/share/7DaysToDie" + "/var/lib/7dtd/serverfiles:/home/sdtdserver/serverfiles" + "/var/lib/7dtd/lgsm:/home/sdtdserver/lgsm/config-lgsm/sdtdserver" + "/var/lib/7dtd/log:/home/sdtdserver/log" + "/var/lib/7dtd/backups:/home/sdtdserver/lgsm/backup" ]; - ports = [ - "9876:9876/udp" - "9877:9877/udp" + "26900:26900/tcp" + "26900:26900/udp" + "26901:26901/udp" + "26902:26902/udp" ]; - environment = { - TZ = "Europe/Stockholm"; - SERVERNAME = "FredOS V-Rising"; - WORLDNAME = "world1"; - # SERVERPASSWORD = ""; + START_MODE = "1"; + VERSION = "stable"; + TimeZone = "Europe/Stockholm"; + TEST_ALERT = "NO"; }; }; }; - ## <----- HYTALE ----> ## - # systemd.services.hytale-server = { - # description = "Hytale Dedicated Server"; - # wantedBy = [ "multi-user.target" ]; - # after = [ "network.target" ]; - # - # path = with pkgs; [ bash jdk unzip gawk gnugrep coreutils screen ]; - # - # environment = { - # HYTALE_MEMORY = "8G"; - # }; - # - # serviceConfig = { - # Type = "forking"; - # User = "fred"; - # Group = "users"; - # WorkingDirectory = "/home/fred/docker/hytale-server/Server"; - # ExecStart = "${pkgs.screen}/bin/screen -dmS hytale /home/fred/docker/hytale-server/start-hytale.sh"; - # ExecStop = "${pkgs.screen}/bin/screen -S hytale -X stuff 'stop^M'"; - # RemainAfterExit = "yes"; - # Restart = "on-failure"; - # RestartSec = "10s"; - # TimeoutStopSec = "30s"; - # - # # Security hardening - # NoNewPrivileges = true; - # PrivateTmp = true; - # }; - # }; + systemd.services."7dtd-configure" = { + description = "Patch 7DTD sdtdserver.xml on first install"; + after = [ "docker-7dtd.service" ]; + wants = [ "docker-7dtd.service" ]; + wantedBy = [ "multi-user.target" ]; + path = with pkgs; [ gnused coreutils systemd ]; + script = '' + MARKER=/var/lib/7dtd/.configured + CONFIG=/var/lib/7dtd/serverfiles/sdtdserver.xml + if [ -f "$MARKER" ]; then + echo "Already configured; skipping." + exit 0 + fi + echo "Waiting for $CONFIG (install can take 15+ minutes on first boot)..." + for i in $(seq 1 180); do + [ -f "$CONFIG" ] && break + sleep 10 + done + if [ ! -f "$CONFIG" ]; then + echo "Timed out waiting for $CONFIG; will retry next boot." + exit 1 + fi - networking.firewall.allowedUDPPorts = [ 9876 9877 ]; + set_prop() { + sed -i "s|