Merge pull request #198835 from YellowOnion/factorio-patch

factorio: better mod support

Changed files
+18 -5
nixos
modules
services
games
pkgs
games
+10 -1
nixos/modules/services/games/factorio.nix
···
} // 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;
in
{
options = {
···
the .zip, named correctly, into the output directory. Eventually,
there will be a way to pull in the most up-to-date list of
derivations via nixos-channel. Until then, this is for experts only.
'';
};
game-name = mkOption {
···
} // 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 cfg.mods-dat;
in
{
options = {
···
the .zip, named correctly, into the output directory. Eventually,
there will be a way to pull in the most up-to-date list of
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 {
+4 -2
pkgs/games/factorio/default.nix
···
, libSM, libICE, libXext, factorio-utils
, releaseType
, mods ? []
, username ? "", token ? "" # get/reset token at https://factorio.com/profile
, experimental ? false # true means to always use the latest branch
}:
···
# 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;
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.");
···
fi
'';
-
modDir = factorio-utils.mkModDirDrv mods;
base = with actual; {
pname = "factorio-${releaseType}";
···
, 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
}:
···
# 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 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.");
···
fi
'';
+
modDir = factorio-utils.mkModDirDrv mods mods-dat;
base = with actual; {
pname = "factorio-${releaseType}";
+4 -2
pkgs/games/factorio/utils.nix
···
{ lib, stdenv }:
with lib;
{
-
mkModDirDrv = mods: # a list of mod derivations
let
recursiveDeps = modDrv: [modDrv] ++ map recursiveDeps modDrv.deps;
modDrvs = unique (flatten (map recursiveDeps mods));
···
# NB: there will only ever be a single zip file in each mod derivation's output dir
ln -s $modDrv/*.zip $out
done
-
'';
};
modDrv = { allRecommendedMods, allOptionalMods }:
···
{ lib, stdenv }:
with lib;
{
+
mkModDirDrv = mods: modsDatFile: # a list of mod derivations
let
recursiveDeps = modDrv: [modDrv] ++ map recursiveDeps modDrv.deps;
modDrvs = unique (flatten (map recursiveDeps mods));
···
# 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 }: