88 lines
2.1 KiB
Nix
88 lines
2.1 KiB
Nix
# 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 = { };
|
|
|
|
networking.firewall = lib.mkIf cfg.openFirewall {
|
|
allowedUDPPorts = [
|
|
15777
|
|
7777
|
|
15000
|
|
];
|
|
};
|
|
};
|
|
}
|