Terraria: Add server container.

This commit is contained in:
Dmitry Voronin 2024-12-02 02:29:53 +03:00
parent 686bb8c9f3
commit 29fa1352d9
4 changed files with 73 additions and 6 deletions

60
container/Terraria.nix Normal file
View file

@ -0,0 +1,60 @@
{
config,
container,
lib,
...
}: let
cfg = config.container.module.terraria;
in {
options.container.module.terraria = {
enable = lib.mkEnableOption "the Terraria server.";
address = lib.mkOption {
default = "10.1.0.77";
type = lib.types.str;
};
port = lib.mkOption {
default = 22777;
type = lib.types.int;
};
storage = lib.mkOption {
default = "${config.container.storage}/terraria";
type = lib.types.str;
};
};
config = lib.mkIf cfg.enable {
systemd.tmpfiles.rules = container.mkContainerDir cfg [
"data"
];
containers.terraria = container.mkContainer cfg {
bindMounts = {
"/var/lib/terraria" = {
hostPath = "${cfg.storage}/data";
isReadOnly = false;
};
};
config = { pkgs, ... }: container.mkContainerConfig cfg {
# NOTE: Admin with `tmux -S /var/lib/terraria/terraria.sock attach-session -t 0`
environment.systemPackages = with pkgs; [ tmux ];
services.terraria = let
dataDir = "/var/lib/terraria";
in {
inherit (cfg) port;
inherit dataDir;
enable = true;
autoCreatedWorldSize = "large";
maxPlayers = 4;
messageOfTheDay = "<3";
noUPnP = false;
openFirewall = false;
password = "mishadima143";
secure = false;
worldPath = "${dataDir}/.local/share/Terraria/Worlds/Together.wld";
};
};
};
};
}

View file

@ -32,6 +32,7 @@
search.enable = true; search.enable = true;
status.enable = true; status.enable = true;
stock.enable = true; stock.enable = true;
terraria.enable = true;
vpn.enable = true; vpn.enable = true;
watch.enable = true; watch.enable = true;
yt.enable = true; yt.enable = true;

View file

@ -216,10 +216,15 @@ in {
+ (mkForward internal cfg.git.portSsh cfg.git.address cfg.git.portSsh tcp) + (mkForward internal cfg.git.portSsh cfg.git.address cfg.git.portSsh tcp)
# Print serivce. # Print serivce.
+ (mkForward internal cfg.print.port cfg.print.address cfg.print.port tcp); + (mkForward internal cfg.print.port cfg.print.address cfg.print.port tcp)
# Terraria server.
+ (mkForward external cfg.terraria.port cfg.terraria.address cfg.terraria.port tcp)
+ (mkForward internal cfg.terraria.port cfg.terraria.address cfg.terraria.port tcp)
# SSH access from WAN. # SSH access from WAN.
# + (mkForward external 22143 config.container.host 22143 tcp) # + (mkForward external 22143 config.container.host 22143 tcp)
;
}; };
}; };
} }

View file

@ -2,7 +2,6 @@
config, config,
const, const,
lib, lib,
pkgs,
util, util,
... ...
}: { }: {
@ -28,13 +27,15 @@
mkContainerConfig = cfg: extra: lib.recursiveUpdate { mkContainerConfig = cfg: extra: lib.recursiveUpdate {
boot.isContainer = true; boot.isContainer = true;
# HACK: Do not evaluate nixpkgs inside the container. Use host's instead.
# nixpkgs.pkgs = lib.mkForce pkgs;
nixpkgs.pkgs = lib.mkForce pkgs;
# Release version. # Release version.
system.stateVersion = const.stateVersion; system.stateVersion = const.stateVersion;
# Nix is fucking annoying.
nixpkgs.config = {
allowUnfree = true;
allowInsecurePredicate = x: true;
};
# Allow passwordless login as root. # Allow passwordless login as root.
users = { users = {
users.root.password = ""; users.root.password = "";