diff options
author | RTUnreal <unreal@rtinf.net> | 2023-11-18 22:18:03 +0100 |
---|---|---|
committer | RTUnreal <unreal@rtinf.net> | 2023-11-18 22:18:03 +0100 |
commit | 20e9267cbb4b145906380b918c08c7904c31fc6f (patch) | |
tree | 09af04898d6c54eed012131903d4c94d3bdb9fad /nixos/modules/services/games | |
parent | adaf0714abcb368b44f5d17301fddf482753de3e (diff) |
factorio: add dynamic server-settings loading
Diffstat (limited to 'nixos/modules/services/games')
-rw-r--r-- | nixos/modules/services/games/factorio.nix | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/nixos/modules/services/games/factorio.nix b/nixos/modules/services/games/factorio.nix index b349ffa2375f..dcbd50ef05ef 100644 --- a/nixos/modules/services/games/factorio.nix +++ b/nixos/modules/services/games/factorio.nix @@ -37,7 +37,8 @@ let autosave_only_on_server = true; non_blocking_saving = cfg.nonBlockingSaving; } // cfg.extraSettings; - serverSettingsFile = pkgs.writeText "server-settings.json" (builtins.toJSON (filterAttrsRecursive (n: v: v != null) serverSettings)); + serverSettingsString = builtins.toJSON (filterAttrsRecursive (n: v: v != null) serverSettings); + serverSettingsFile = pkgs.writeText "server-settings.json"; serverAdminsFile = pkgs.writeText "server-adminlist.json" (builtins.toJSON cfg.admins); modDir = pkgs.factorio-utils.mkModDirDrv cfg.mods cfg.mods-dat; in @@ -115,6 +116,16 @@ in customizations. ''; }; + extraSettingsFile = mkOption { + type = types.nullOr types.path; + default = null; + description = lib.mdDoc '' + File, which is dynamically applied to server-settings.json before + startup. + + This option should be used for credentials. + ''; + }; stateDirName = mkOption { type = types.str; default = "factorio"; @@ -186,6 +197,8 @@ in default = null; description = lib.mdDoc '' Your factorio.com login credentials. Required for games with visibility public. + + This option is unsecure. Use extraSettingsFile instead. ''; }; package = mkOption { @@ -202,6 +215,8 @@ in default = null; description = lib.mdDoc '' Your factorio.com login credentials. Required for games with visibility public. + + This option is unsecure. Use extraSettingsFile instead. ''; }; token = mkOption { @@ -216,6 +231,8 @@ in default = null; description = lib.mdDoc '' Game password. + + This option is unsecure. Use extraSettingsFile instead. ''; }; requireUserVerification = mkOption { @@ -251,14 +268,18 @@ in wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; - preStart = toString [ - "test -e ${stateDir}/saves/${cfg.saveName}.zip" - "||" - "${cfg.package}/bin/factorio" + preStart = + toString [ + "test -e ${stateDir}/saves/${cfg.saveName}.zip" + "||" + "${cfg.package}/bin/factorio" "--config=${cfg.configFile}" "--create=${mkSavePath cfg.saveName}" (optionalString (cfg.mods != []) "--mod-directory=${modDir}") - ]; + ] + + (optionalString hasExtraSettings ("\necho ${lib.strings.escapeShellArgs serverSettingsString}" + + " \"$(cat ${cfg.extraSettingsFile})\" | ${lib.getExe pkgs.jq} -s add" + + " > ${stateDir}/server-settings.json")); serviceConfig = { Restart = "always"; @@ -272,7 +293,11 @@ in "--port=${toString cfg.port}" "--bind=${cfg.bind}" (optionalString (!cfg.loadLatestSave) "--start-server=${mkSavePath cfg.saveName}") - "--server-settings=${serverSettingsFile}" + "--server-settings=${ + if hasExtraSettings + then "${stateDir}/server-settings.json" + else serverSettingsFile + }" (optionalString cfg.loadLatestSave "--start-server-load-latest") (optionalString (cfg.mods != []) "--mod-directory=${modDir}") (optionalString (cfg.admins != []) "--server-adminlist=${serverAdminsFile}") |