Merge pull request #77478 from artemist/nixos-factorio

nixos/factorio: add extraSettings and package options
This commit is contained in:
Dmitry Kalinkin 2020-03-30 15:36:16 -04:00 committed by GitHub
commit 61a79754bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,14 +4,13 @@ with lib;
let let
cfg = config.services.factorio; cfg = config.services.factorio;
factorio = pkgs.factorio-headless;
name = "Factorio"; name = "Factorio";
stateDir = "/var/lib/${cfg.stateDirName}"; stateDir = "/var/lib/${cfg.stateDirName}";
mkSavePath = name: "${stateDir}/saves/${name}.zip"; mkSavePath = name: "${stateDir}/saves/${name}.zip";
configFile = pkgs.writeText "factorio.conf" '' configFile = pkgs.writeText "factorio.conf" ''
use-system-read-write-data-directories=true use-system-read-write-data-directories=true
[path] [path]
read-data=${factorio}/share/factorio/data read-data=${cfg.package}/share/factorio/data
write-data=${stateDir} write-data=${stateDir}
''; '';
serverSettings = { serverSettings = {
@ -37,7 +36,7 @@ let
only_admins_can_pause_the_game = true; only_admins_can_pause_the_game = true;
autosave_only_on_server = true; autosave_only_on_server = true;
admins = []; admins = [];
}; } // cfg.extraSettings;
serverSettingsFile = pkgs.writeText "server-settings.json" (builtins.toJSON (filterAttrsRecursive (n: v: v != null) serverSettings)); serverSettingsFile = pkgs.writeText "server-settings.json" (builtins.toJSON (filterAttrsRecursive (n: v: v != null) serverSettings));
modDir = pkgs.factorio-utils.mkModDirDrv cfg.mods; modDir = pkgs.factorio-utils.mkModDirDrv cfg.mods;
in in
@ -115,6 +114,14 @@ in
Description of the game that will appear in the listing. Description of the game that will appear in the listing.
''; '';
}; };
extraSettings = mkOption {
type = types.attrs;
default = {};
example = { admins = [ "username" ];};
description = ''
Extra game configuration that will go into server-settings.json
'';
};
public = mkOption { public = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
@ -136,6 +143,15 @@ in
Your factorio.com login credentials. Required for games with visibility public. Your factorio.com login credentials. Required for games with visibility public.
''; '';
}; };
package = mkOption {
type = types.package;
default = pkgs.factorio-headless;
defaultText = "pkgs.factorio-headless";
example = "pkgs.factorio-headless-experimental";
description = ''
Factorio version to use. This defaults to the stable channel.
'';
};
password = mkOption { password = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
@ -184,7 +200,7 @@ in
preStart = toString [ preStart = toString [
"test -e ${stateDir}/saves/${cfg.saveName}.zip" "test -e ${stateDir}/saves/${cfg.saveName}.zip"
"||" "||"
"${factorio}/bin/factorio" "${cfg.package}/bin/factorio"
"--config=${cfg.configFile}" "--config=${cfg.configFile}"
"--create=${mkSavePath cfg.saveName}" "--create=${mkSavePath cfg.saveName}"
(optionalString (cfg.mods != []) "--mod-directory=${modDir}") (optionalString (cfg.mods != []) "--mod-directory=${modDir}")
@ -197,7 +213,7 @@ in
StateDirectory = cfg.stateDirName; StateDirectory = cfg.stateDirName;
UMask = "0007"; UMask = "0007";
ExecStart = toString [ ExecStart = toString [
"${factorio}/bin/factorio" "${cfg.package}/bin/factorio"
"--config=${cfg.configFile}" "--config=${cfg.configFile}"
"--port=${toString cfg.port}" "--port=${toString cfg.port}"
"--start-server=${mkSavePath cfg.saveName}" "--start-server=${mkSavePath cfg.saveName}"