diff --git a/common.nix b/common.nix index 1a89862..ac47cfc 100644 --- a/common.nix +++ b/common.nix @@ -19,6 +19,7 @@ # Services # ./services/server-permissions.nix ./services/game-servers.nix + ./services/dr-server.nix ./services/qbittorrent-nox.nix ./services/nginx.nix ./services/go2rtc.nix diff --git a/services/dr-server.nix b/services/dr-server.nix new file mode 100644 index 0000000..548e6ac --- /dev/null +++ b/services/dr-server.nix @@ -0,0 +1,69 @@ +{ config, pkgs, lib, ... }: +let + wine = pkgs.wineWowPackages.stable; + dataDir = "/var/lib/dr-server"; + buildDir = "${dataDir}/Build"; + prefix = "${dataDir}/wine"; + logDir = "${dataDir}/log"; +in +{ + config = lib.mkIf (config.networking.hostName == "FredOS-Mediaserver") { + users.users.dr-server = { + isSystemUser = true; + group = "dr-server"; + home = dataDir; + description = "Dungeon Runners Reborn server"; + }; + users.groups.dr-server = {}; + + systemd.tmpfiles.rules = [ + "d ${dataDir} 0750 dr-server dr-server -" + "d ${buildDir} 0750 dr-server dr-server -" + "d ${prefix} 0750 dr-server dr-server -" + "d ${logDir} 0750 dr-server dr-server -" + ]; + + ## <----- DUNGEON RUNNERS REBORN ----> ## + # Windows-only Unity build run headless under Wine. Initializes a + # Win64 prefix on first boot via wineboot, then launches the exe + # with Unity's batch flags. Only the friend's exe is in this tree — + # the matching client is needed on connecting machines. + systemd.services.dr-server = { + description = "Dungeon Runners Reborn (Wine, headless Unity)"; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + + path = [ wine pkgs.coreutils ]; + environment = { + WINEPREFIX = prefix; + WINEARCH = "win64"; + WINEDEBUG = "-all"; + HOME = dataDir; + DISPLAY = ""; + }; + + preStart = '' + if [ ! -f "${prefix}/system.reg" ]; then + ${wine}/bin/wineboot --init + ${wine}/bin/wineserver -w + fi + ''; + + unitConfig.ConditionPathExists = "${buildDir}/DR_Server.exe"; + + serviceConfig = { + Type = "simple"; + User = "dr-server"; + Group = "dr-server"; + WorkingDirectory = buildDir; + ExecStart = "${wine}/bin/wine64 DR_Server.exe -batchmode -nographics -logFile ${logDir}/server.log"; + Restart = "on-failure"; + RestartSec = "10s"; + }; + }; + + networking.firewall.allowedTCPPorts = [ 2110 2603 2604 2605 2606 ]; + networking.firewall.allowedUDPPorts = [ 2110 2603 2604 2605 2606 ]; + }; +}