Merge pull request #17479 from elitak/factorio

Factorio: 0.13.8 -> 0.13.13, mod support
This commit is contained in:
Rok Garbas
2016-08-07 04:09:52 +02:00
committed by GitHub
5 changed files with 331 additions and 19 deletions
+38 -10
View File
@@ -4,14 +4,17 @@ with lib;
let
cfg = config.services.factorio;
factorio = pkgs.factorio-headless;
name = "Factorio";
stateDir = "/var/lib/factorio";
mkSavePath = name: "${stateDir}/saves/${name}.zip";
configFile = pkgs.writeText "factorio.conf" ''
use-system-read-write-data-directories=true
[path]
read-data=${pkgs.factorio-headless}/share/factorio/data
read-data=${factorio}/share/factorio/data
write-data=${stateDir}
'';
modDir = pkgs.factorio-mkModDirDrv cfg.mods;
in
{
options = {
@@ -32,7 +35,8 @@ in
description = ''
The name of the savegame that will be used by the server.
When not present in ${stateDir}/saves, it will be generated before starting the service.
When not present in ${stateDir}/saves, a new map with default
settings will be generated before starting the service.
'';
};
# TODO Add more individual settings as nixos-options?
@@ -51,6 +55,26 @@ in
customizations.
'';
};
mods = mkOption {
type = types.listOf types.package;
default = [];
description = ''
Mods the server should install and activate.
The derivations in this list must "build" the mod by simply copying
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.
'';
};
autosave-interval = mkOption {
type = types.nullOr types.int;
default = null;
example = 2;
description = ''
The time, in minutes, between autosaves.
'';
};
};
};
@@ -74,12 +98,14 @@ in
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
preStart = ''
test -e ${stateDir}/saves/${cfg.saveName}.zip || \
${pkgs.factorio-headless}/bin/factorio \
--config=${cfg.configFile} \
--create=${stateDir}/saves/${cfg.saveName}.zip
'';
preStart = toString [
"test -e ${stateDir}/saves/${cfg.saveName}.zip"
"||"
"${factorio}/bin/factorio"
"--config=${cfg.configFile}"
"--create=${mkSavePath cfg.saveName}"
(optionalString (cfg.mods != []) "--mod-directory=${modDir}")
];
serviceConfig = {
User = "factorio";
@@ -90,10 +116,12 @@ in
PrivateTmp = true;
UMask = "0007";
ExecStart = toString [
"${pkgs.factorio-headless}/bin/factorio"
"${factorio}/bin/factorio"
"--config=${cfg.configFile}"
"--port=${toString cfg.port}"
"--start-server=${stateDir}/saves/${cfg.saveName}.zip"
"--start-server=${mkSavePath cfg.saveName}"
(optionalString (cfg.mods != []) "--mod-directory=${modDir}")
(optionalString (cfg.autosave-interval != null) "--autosave-interval ${toString cfg.autosave-interval}")
];
};
};