connect on ip:7777
{ config, pkgs, lib, ... }:
let
cfg = config.services.satisfactory;
installDir = "/var/lib/satisfactory/SatisfactoryDedicatedServer";
configDir = "${installDir}/FactoryGame/Saved/Config/LinuxServer";
in
{
options.services.satisfactory = {
enable = lib.mkEnableOption "Satisfactory Dedicated Server";
beta = lib.mkOption {
type = lib.types.enum [ "public" "experimental" ];
default = "public";
description = "Steam branch to use.";
};
address = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = "IP address to bind the server to.";
};
maxPlayers = lib.mkOption {
type = lib.types.int;
default = 4;
description = "Maximum number of players.";
};
autoPause = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Pause the game when no players are online.";
};
autoSaveOnDisconnect = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Save the game when a player disconnects.";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Open the required firewall ports.";
};
};
config = lib.mkIf cfg.enable {
users.users.satisfactory = {
home = "/var/lib/satisfactory";
createHome = true;
isSystemUser = true;
group = "satisfactory";
};
users.groups.satisfactory = {};
nixpkgs.config.allowUnfree = true;
networking.firewall = lib.mkIf cfg.openFirewall {
allowedUDPPorts = [ 7777 15000 15777 ];
allowedTCPPorts = [ 7777 ];
};
systemd.services.satisfactory = {
description = "Satisfactory Dedicated Server";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
preStart = ''
# Download / update server files
${pkgs.steamcmd}/bin/steamcmd \
+force_install_dir ${installDir} \
+login anonymous \
+app_update 1690800 \
-beta ${cfg.beta} \
validate \
+quit
# Patch the ELF interpreter so the binary finds glibc
${pkgs.patchelf}/bin/patchelf \
--set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 \
${installDir}/Engine/Binaries/Linux/FactoryServer-Linux-Shipping
# Steam SDK symlink expected by the server
mkdir -p /var/lib/satisfactory/.steam/steam
ln -sfv /var/lib/satisfactory/.steam/steam/linux64 \
/var/lib/satisfactory/.steam/sdk64
# Write server config
mkdir -p ${configDir}
${pkgs.crudini}/bin/crudini --set \
${configDir}/Game.ini \
'/Script/Engine.GameSession' \
MaxPlayers \
${toString cfg.maxPlayers}
${pkgs.crudini}/bin/crudini --set \
${configDir}/ServerSettings.ini \
'/Script/FactoryGame.FGServerSubsystem' \
mAutoPause \
${if cfg.autoPause then "True" else "False"}
${pkgs.crudini}/bin/crudini --set \
${configDir}/ServerSettings.ini \
'/Script/FactoryGame.FGServerSubsystem' \
mAutoSaveOnDisconnect \
${if cfg.autoSaveOnDisconnect then "True" else "False"}
'';
script = ''
${installDir}/Engine/Binaries/Linux/FactoryServer-Linux-Shipping \
FactoryGame \
-multihome=${cfg.address} \
-ServerQueryPort=15777 \
-BeaconPort=15000 \
-Port=7777
'';
serviceConfig = {
User = "satisfactory";
Group = "satisfactory";
WorkingDirectory = "/var/lib/satisfactory";
Restart = "always";
RestartSec = "10s";
Nice = "-5";
};
environment = {
LD_LIBRARY_PATH = lib.concatStringsSep ":" [
"${installDir}/linux64"
"${installDir}/Engine/Binaries/Linux"
"${installDir}/Engine/Binaries/ThirdParty/PhysX3/Linux/x86_64-unknown-linux-gnu"
];
};
};
};
} imports = [ ./satisfactory.nix ];
services.satisfactory = {
enable = true;
maxPlayers = 4;
autoPause = true;
openFirewall = true;
};