diff --git a/container/Terraria.nix b/container/Terraria.nix new file mode 100644 index 0000000..7636c5d --- /dev/null +++ b/container/Terraria.nix @@ -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"; + }; + }; + }; + }; +} diff --git a/host/x86_64-linux/home/Container.nix b/host/x86_64-linux/home/Container.nix index 1b64a9a..b187616 100644 --- a/host/x86_64-linux/home/Container.nix +++ b/host/x86_64-linux/home/Container.nix @@ -32,6 +32,7 @@ search.enable = true; status.enable = true; stock.enable = true; + terraria.enable = true; vpn.enable = true; watch.enable = true; yt.enable = true; diff --git a/host/x86_64-linux/home/Network.nix b/host/x86_64-linux/home/Network.nix index 49be786..9e86fab 100644 --- a/host/x86_64-linux/home/Network.nix +++ b/host/x86_64-linux/home/Network.nix @@ -216,10 +216,15 @@ in { + (mkForward internal cfg.git.portSsh cfg.git.address cfg.git.portSsh tcp) # 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. # + (mkForward external 22143 config.container.host 22143 tcp) + ; }; }; } diff --git a/lib/Container.nix b/lib/Container.nix index 1389279..bfb0436 100644 --- a/lib/Container.nix +++ b/lib/Container.nix @@ -2,7 +2,6 @@ config, const, lib, - pkgs, util, ... }: { @@ -28,13 +27,15 @@ mkContainerConfig = cfg: extra: lib.recursiveUpdate { 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. system.stateVersion = const.stateVersion; + # Nix is fucking annoying. + nixpkgs.config = { + allowUnfree = true; + allowInsecurePredicate = x: true; + }; + # Allow passwordless login as root. users = { users.root.password = "";