diff --git a/nixos/modules/services/games/terraria.nix b/nixos/modules/services/games/terraria.nix index 4c32cc92a1b9..144186dc7701 100644 --- a/nixos/modules/services/games/terraria.nix +++ b/nixos/modules/services/games/terraria.nix @@ -1,13 +1,10 @@ { config, lib, options, pkgs, ... }: - -with lib; - let cfg = config.services.terraria; opt = options.services.terraria; worldSizeMap = { small = 1; medium = 2; large = 3; }; - valFlag = name: val: optionalString (val != null) "-${name} \"${escape ["\\" "\""] (toString val)}\""; - boolFlag = name: val: optionalString val "-${name}"; + valFlag = name: val: lib.optionalString (val != null) "-${name} \"${lib.escape ["\\" "\""] (toString val)}\""; + boolFlag = name: val: lib.optionalString val "-${name}"; flags = [ (valFlag "port" cfg.port) (valFlag "maxPlayers" cfg.maxPlayers) @@ -46,8 +43,8 @@ in { options = { services.terraria = { - enable = mkOption { - type = types.bool; + enable = lib.mkOption { + type = lib.types.bool; default = false; description = '' If enabled, starts a Terraria server. The server can be connected to via `tmux -S ''${config.${opt.dataDir}}/terraria.sock attach` @@ -55,40 +52,40 @@ in ''; }; - port = mkOption { - type = types.port; + port = lib.mkOption { + type = lib.types.port; default = 7777; description = '' Specifies the port to listen on. ''; }; - maxPlayers = mkOption { - type = types.ints.u8; + maxPlayers = lib.mkOption { + type = lib.types.ints.u8; default = 255; description = '' Sets the max number of players (between 1 and 255). ''; }; - password = mkOption { - type = types.nullOr types.str; + password = lib.mkOption { + type = lib.types.nullOr lib.types.str; default = null; description = '' Sets the server password. Leave `null` for no password. ''; }; - messageOfTheDay = mkOption { - type = types.nullOr types.str; + messageOfTheDay = lib.mkOption { + type = lib.types.nullOr lib.types.str; default = null; description = '' Set the server message of the day text. ''; }; - worldPath = mkOption { - type = types.nullOr types.path; + worldPath = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; description = '' The path to the world file (`.wld`) which should be loaded. @@ -97,8 +94,8 @@ in ''; }; - autoCreatedWorldSize = mkOption { - type = types.enum [ "small" "medium" "large" ]; + autoCreatedWorldSize = lib.mkOption { + type = lib.types.enum [ "small" "medium" "large" ]; default = "medium"; description = '' Specifies the size of the auto-created world if `worldPath` does not @@ -106,34 +103,34 @@ in ''; }; - banListPath = mkOption { - type = types.nullOr types.path; + banListPath = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; description = '' The path to the ban list. ''; }; - secure = mkOption { - type = types.bool; + secure = lib.mkOption { + type = lib.types.bool; default = false; description = "Adds additional cheat protection to the server."; }; - noUPnP = mkOption { - type = types.bool; + noUPnP = lib.mkOption { + type = lib.types.bool; default = false; description = "Disables automatic Universal Plug and Play."; }; - openFirewall = mkOption { - type = types.bool; + openFirewall = lib.mkOption { + type = lib.types.bool; default = false; description = "Whether to open ports in the firewall"; }; - dataDir = mkOption { - type = types.str; + dataDir = lib.mkOption { + type = lib.types.str; default = "/var/lib/terraria"; example = "/srv/terraria"; description = "Path to variable state data directory for terraria."; @@ -141,7 +138,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { users.users.terraria = { description = "Terraria server service user"; group = "terraria"; @@ -165,12 +162,12 @@ in Type = "forking"; GuessMainPID = true; UMask = 007; - ExecStart = "${tmuxCmd} new -d ${pkgs.terraria-server}/bin/TerrariaServer ${concatStringsSep " " flags}"; + ExecStart = "${tmuxCmd} new -d ${pkgs.terraria-server}/bin/TerrariaServer ${lib.concatStringsSep " " flags}"; ExecStop = "${stopScript} $MAINPID"; }; }; - networking.firewall = mkIf cfg.openFirewall { + networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; allowedUDPPorts = [ cfg.port ]; };