diff --git a/nixos/modules/services/games/factorio.nix b/nixos/modules/services/games/factorio.nix index 844fd2bce517..9b15cac149d5 100644 --- a/nixos/modules/services/games/factorio.nix +++ b/nixos/modules/services/games/factorio.nix @@ -39,7 +39,7 @@ let } // cfg.extraSettings; serverSettingsFile = pkgs.writeText "server-settings.json" (builtins.toJSON (filterAttrsRecursive (n: v: v != null) serverSettings)); serverAdminsFile = pkgs.writeText "server-adminlist.json" (builtins.toJSON cfg.admins); - modDir = pkgs.factorio-utils.mkModDirDrv cfg.mods; + modDir = pkgs.factorio-utils.mkModDirDrv cfg.mods cfg.mods-dat; in { options = { @@ -136,6 +136,15 @@ in derivations via nixos-channel. Until then, this is for experts only. ''; }; + mods-dat = mkOption { + type = types.nullOr types.path; + default = null; + description = lib.mdDoc '' + Mods settings can be changed by specifying a dat file, in the [mod + settings file + format](https://wiki.factorio.com/Mod_settings_file_format). + ''; + }; game-name = mkOption { type = types.nullOr types.str; default = "Factorio Game"; diff --git a/pkgs/games/factorio/default.nix b/pkgs/games/factorio/default.nix index 17f9947b4982..a65ce6bac0db 100644 --- a/pkgs/games/factorio/default.nix +++ b/pkgs/games/factorio/default.nix @@ -3,6 +3,8 @@ , libSM, libICE, libXext, factorio-utils , releaseType , mods ? [] +, mods-dat ? null +, versionsJson ? ./versions.json , username ? "", token ? "" # get/reset token at https://factorio.com/profile , experimental ? false # true means to always use the latest branch }: @@ -60,7 +62,7 @@ let # NB `experimental` directs us to take the latest build, regardless of its branch; # hence the (stable, experimental) pairs may sometimes refer to the same distributable. - versions = importJSON ./versions.json; + versions = importJSON versionsJson; binDists = makeBinDists versions; actual = binDists.${stdenv.hostPlatform.system}.${releaseType}.${branch} or (throw "Factorio ${releaseType}-${branch} binaries for ${stdenv.hostPlatform.system} are not available for download."); @@ -129,7 +131,7 @@ let fi ''; - modDir = factorio-utils.mkModDirDrv mods; + modDir = factorio-utils.mkModDirDrv mods mods-dat; base = with actual; { pname = "factorio-${releaseType}"; diff --git a/pkgs/games/factorio/utils.nix b/pkgs/games/factorio/utils.nix index be5b7fd5eccc..d2b52ae48366 100644 --- a/pkgs/games/factorio/utils.nix +++ b/pkgs/games/factorio/utils.nix @@ -3,7 +3,7 @@ { lib, stdenv }: with lib; { - mkModDirDrv = mods: # a list of mod derivations + mkModDirDrv = mods: modsDatFile: # a list of mod derivations let recursiveDeps = modDrv: [modDrv] ++ map recursiveDeps modDrv.deps; modDrvs = unique (flatten (map recursiveDeps mods)); @@ -18,7 +18,9 @@ with lib; # NB: there will only ever be a single zip file in each mod derivation's output dir ln -s $modDrv/*.zip $out done - ''; + '' + (lib.optionalString (modsDatFile != null) '' + cp ${modsDatFile} $out/mod-settings.dat + ''); }; modDrv = { allRecommendedMods, allOptionalMods }: