From 58291c04d29573796065bf5194256e0ee834608c Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Sat, 14 Sep 2024 11:58:03 +0100 Subject: [PATCH] Add and enable Satisfactory dedicated server Add steamcmd to allowed unfree packages --- system/Legion.nix | 3 +- system/default.nix | 1 + system/services/satisfactory/default.nix | 9 +++ system/services/satisfactory/module.nix | 87 ++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 system/services/satisfactory/default.nix create mode 100644 system/services/satisfactory/module.nix diff --git a/system/Legion.nix b/system/Legion.nix index 4c86aadb..712d614a 100644 --- a/system/Legion.nix +++ b/system/Legion.nix @@ -7,10 +7,9 @@ ./services/home-assistant.nix ./services/minecraft.nix ./services/nix-serve.nix - # ./services/radicale.nix + ./services/satisfactory/default.nix ./services/sshd.nix ./services/syncthing.nix - # ./services/znc.nix ]; boot.loader = { systemd-boot.enable = true; diff --git a/system/default.nix b/system/default.nix index d47bf2f5..30440750 100644 --- a/system/default.nix +++ b/system/default.nix @@ -59,6 +59,7 @@ "steam" "steam-original" "steam-run" + "steamcmd" ]; overlays = [ (final: prev: { inherit (inputs.plasma-manager.packages.${prev.system}) rc2nix; }) ]; }; diff --git a/system/services/satisfactory/default.nix b/system/services/satisfactory/default.nix new file mode 100644 index 00000000..188311b6 --- /dev/null +++ b/system/services/satisfactory/default.nix @@ -0,0 +1,9 @@ +{ ... }: +{ + imports = [ ./module.nix ]; + services.satisfactory-server = { + enable = true; + openFirewall = true; + launchOptions = "-multihome=0.0.0.0"; + }; +} diff --git a/system/services/satisfactory/module.nix b/system/services/satisfactory/module.nix new file mode 100644 index 00000000..bf445c8f --- /dev/null +++ b/system/services/satisfactory/module.nix @@ -0,0 +1,87 @@ +# 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 + ]; + }; + }; +}