nixos/services.factorio: remove with lib;
(#338052)
This commit is contained in:
commit
e65bab0ec8
@ -1,7 +1,4 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.factorio;
|
||||
name = "Factorio";
|
||||
@ -37,7 +34,7 @@ let
|
||||
autosave_only_on_server = true;
|
||||
non_blocking_saving = cfg.nonBlockingSaving;
|
||||
} // cfg.extraSettings;
|
||||
serverSettingsString = builtins.toJSON (filterAttrsRecursive (n: v: v != null) serverSettings);
|
||||
serverSettingsString = builtins.toJSON (lib.filterAttrsRecursive (n: v: v != null) serverSettings);
|
||||
serverSettingsFile = pkgs.writeText "server-settings.json" serverSettingsString;
|
||||
serverAdminsFile = pkgs.writeText "server-adminlist.json" (builtins.toJSON cfg.admins);
|
||||
modDir = pkgs.factorio-utils.mkModDirDrv cfg.mods cfg.mods-dat;
|
||||
@ -45,25 +42,25 @@ in
|
||||
{
|
||||
options = {
|
||||
services.factorio = {
|
||||
enable = mkEnableOption name;
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
enable = lib.mkEnableOption name;
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 34197;
|
||||
description = ''
|
||||
The port to which the service should bind.
|
||||
'';
|
||||
};
|
||||
|
||||
bind = mkOption {
|
||||
type = types.str;
|
||||
bind = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "0.0.0.0";
|
||||
description = ''
|
||||
The address to which the service should bind.
|
||||
'';
|
||||
};
|
||||
|
||||
admins = mkOption {
|
||||
type = types.listOf types.str;
|
||||
admins = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [];
|
||||
example = [ "username" ];
|
||||
description = ''
|
||||
@ -71,15 +68,15 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
openFirewall = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to automatically open the specified UDP port in the firewall.
|
||||
'';
|
||||
};
|
||||
saveName = mkOption {
|
||||
type = types.str;
|
||||
saveName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "default";
|
||||
description = ''
|
||||
The name of the savegame that will be used by the server.
|
||||
@ -88,8 +85,8 @@ in
|
||||
a new map with default settings will be generated before starting the service.
|
||||
'';
|
||||
};
|
||||
loadLatestSave = mkOption {
|
||||
type = types.bool;
|
||||
loadLatestSave = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Load the latest savegame on startup. This overrides saveName, in that the latest
|
||||
@ -104,10 +101,10 @@ in
|
||||
# TODO XXX The server tries to copy a newly created config file over the old one
|
||||
# on shutdown, but fails, because it's in the nix store. When is this needed?
|
||||
# Can an admin set options in-game and expect to have them persisted?
|
||||
configFile = mkOption {
|
||||
type = types.path;
|
||||
configFile = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = configFile;
|
||||
defaultText = literalExpression "configFile";
|
||||
defaultText = lib.literalExpression "configFile";
|
||||
description = ''
|
||||
The server's configuration file.
|
||||
|
||||
@ -116,8 +113,8 @@ in
|
||||
customizations.
|
||||
'';
|
||||
};
|
||||
extraSettingsFile = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
extraSettingsFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
File, which is dynamically applied to server-settings.json before
|
||||
@ -133,8 +130,8 @@ in
|
||||
```
|
||||
'';
|
||||
};
|
||||
stateDirName = mkOption {
|
||||
type = types.str;
|
||||
stateDirName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "factorio";
|
||||
description = ''
|
||||
Name of the directory under /var/lib holding the server's data.
|
||||
@ -142,8 +139,8 @@ in
|
||||
The configuration and map will be stored here.
|
||||
'';
|
||||
};
|
||||
mods = mkOption {
|
||||
type = types.listOf types.package;
|
||||
mods = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.package;
|
||||
default = [];
|
||||
description = ''
|
||||
Mods the server should install and activate.
|
||||
@ -154,8 +151,8 @@ in
|
||||
derivations via nixos-channel. Until then, this is for experts only.
|
||||
'';
|
||||
};
|
||||
mods-dat = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
mods-dat = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
Mods settings can be changed by specifying a dat file, in the [mod
|
||||
@ -163,44 +160,44 @@ in
|
||||
format](https://wiki.factorio.com/Mod_settings_file_format).
|
||||
'';
|
||||
};
|
||||
game-name = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
game-name = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "Factorio Game";
|
||||
description = ''
|
||||
Name of the game as it will appear in the game listing.
|
||||
'';
|
||||
};
|
||||
description = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
description = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
Description of the game that will appear in the listing.
|
||||
'';
|
||||
};
|
||||
extraSettings = mkOption {
|
||||
type = types.attrs;
|
||||
extraSettings = lib.mkOption {
|
||||
type = lib.types.attrs;
|
||||
default = {};
|
||||
example = { admins = [ "username" ];};
|
||||
description = ''
|
||||
Extra game configuration that will go into server-settings.json
|
||||
'';
|
||||
};
|
||||
public = mkOption {
|
||||
type = types.bool;
|
||||
public = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Game will be published on the official Factorio matching server.
|
||||
'';
|
||||
};
|
||||
lan = mkOption {
|
||||
type = types.bool;
|
||||
lan = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Game will be broadcast on LAN.
|
||||
'';
|
||||
};
|
||||
username = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
username = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Your factorio.com login credentials. Required for games with visibility public.
|
||||
@ -208,11 +205,11 @@ in
|
||||
This option is insecure. Use extraSettingsFile instead.
|
||||
'';
|
||||
};
|
||||
package = mkPackageOption pkgs "factorio-headless" {
|
||||
package = lib.mkPackageOption pkgs "factorio-headless" {
|
||||
example = "factorio-headless-experimental";
|
||||
};
|
||||
password = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
password = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Your factorio.com login credentials. Required for games with visibility public.
|
||||
@ -220,15 +217,15 @@ in
|
||||
This option is insecure. Use extraSettingsFile instead.
|
||||
'';
|
||||
};
|
||||
token = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
token = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Authentication token. May be used instead of 'password' above.
|
||||
'';
|
||||
};
|
||||
game-password = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
game-password = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Game password.
|
||||
@ -236,23 +233,23 @@ in
|
||||
This option is insecure. Use extraSettingsFile instead.
|
||||
'';
|
||||
};
|
||||
requireUserVerification = mkOption {
|
||||
type = types.bool;
|
||||
requireUserVerification = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
When set to true, the server will only allow clients that have a valid factorio.com account.
|
||||
'';
|
||||
};
|
||||
autosave-interval = mkOption {
|
||||
type = types.nullOr types.int;
|
||||
autosave-interval = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.int;
|
||||
default = null;
|
||||
example = 10;
|
||||
description = ''
|
||||
Autosave interval in minutes.
|
||||
'';
|
||||
};
|
||||
nonBlockingSaving = mkOption {
|
||||
type = types.bool;
|
||||
nonBlockingSaving = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Highly experimental feature, enable only at your own risk of losing your saves.
|
||||
@ -263,7 +260,7 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.factorio = {
|
||||
description = "Factorio headless server";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
@ -276,9 +273,9 @@ in
|
||||
"${cfg.package}/bin/factorio"
|
||||
"--config=${cfg.configFile}"
|
||||
"--create=${mkSavePath cfg.saveName}"
|
||||
(optionalString (cfg.mods != []) "--mod-directory=${modDir}")
|
||||
(lib.optionalString (cfg.mods != []) "--mod-directory=${modDir}")
|
||||
])
|
||||
+ (optionalString (cfg.extraSettingsFile != null) ("\necho ${lib.strings.escapeShellArg serverSettingsString}"
|
||||
+ (lib.optionalString (cfg.extraSettingsFile != null) ("\necho ${lib.strings.lib.escapeShellArg serverSettingsString}"
|
||||
+ " \"$(cat ${cfg.extraSettingsFile})\" | ${lib.getExe pkgs.jq} -s add"
|
||||
+ " > ${stateDir}/server-settings.json"));
|
||||
|
||||
@ -293,15 +290,15 @@ in
|
||||
"--config=${cfg.configFile}"
|
||||
"--port=${toString cfg.port}"
|
||||
"--bind=${cfg.bind}"
|
||||
(optionalString (!cfg.loadLatestSave) "--start-server=${mkSavePath cfg.saveName}")
|
||||
(lib.optionalString (!cfg.loadLatestSave) "--start-server=${mkSavePath cfg.saveName}")
|
||||
"--server-settings=${
|
||||
if (cfg.extraSettingsFile != null)
|
||||
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}")
|
||||
(lib.optionalString cfg.loadLatestSave "--start-server-load-latest")
|
||||
(lib.optionalString (cfg.mods != []) "--mod-directory=${modDir}")
|
||||
(lib.optionalString (cfg.admins != []) "--server-adminlist=${serverAdminsFile}")
|
||||
];
|
||||
|
||||
# Sandboxing
|
||||
@ -320,6 +317,6 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall.allowedUDPPorts = optional cfg.openFirewall cfg.port;
|
||||
networking.firewall.allowedUDPPorts = lib.optional cfg.openFirewall cfg.port;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user