nixos/system/services/satisfactory/module.nix

93 lines
2.2 KiB
Nix
Raw Normal View History

# From: https://gitlab.kuca.cz/tom-kuca/nix-config/-/blob/a11e73470c4f9a151afe67c7fa3a960b838d0d98/modules/nixos/satisfactory.nix
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.satisfactory-server;
in
{
options.services.satisfactory-server = {
enable = lib.mkEnableOption "Satisfactory Dedicated Server";
steamcmdPackage = lib.mkOption {
type = lib.types.package;
default = pkgs.steamcmd;
defaultText = "pkgs.steamcmd";
description = ''
The package implementing SteamCMD
'';
};
dataDir = lib.mkOption {
type = lib.types.path;
description = "Directory to store game server";
default = "/var/lib/satisfactory";
};
launchOptions = lib.mkOption {
type = lib.types.str;
description = "Launch options to use.";
default = "";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to open ports in the firewall for the server
'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.satisfactory-server =
let
steamcmd = "${cfg.steamcmdPackage}/bin/steamcmd";
steam-run = "${pkgs.steam-run}/bin/steam-run";
in
{
description = "Satisfactory Dedicated Server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
TimeoutSec = "15min";
ExecStart = "${steam-run} ${cfg.dataDir}/FactoryServer.sh ${cfg.launchOptions}";
Restart = "always";
User = "satisfactory";
WorkingDirectory = cfg.dataDir;
};
preStart = ''
${steamcmd} +force_install_dir "${cfg.dataDir}" +login anonymous +app_update 1690800 validate +quit
'';
};
users.users.satisfactory = {
description = "Satisfactory server service user";
home = cfg.dataDir;
createHome = true;
isSystemUser = true;
group = "satisfactory";
};
users.groups.satisfactory = { };
2024-09-14 19:06:46 +01:00
networking.firewall =
let
ports = [
7777
15000
15777
];
in
lib.mkIf cfg.openFirewall {
allowedTCPPorts = ports;
allowedUDPPorts = ports;
};
};
}