git.iko.soy/typeable/nixpkgs
on master help sign in
Add Terraria server service (#16832)
commit486b8e7f5cd4d2a476c1f0fd50f71273d575d0e3 authorPaul Hendry <paul@pshendry.com> dateSat 6 Aug 2016, 18:58 (10 years ago) parentd21981c
4 files changed+143
nixos/modules/misc/ids.nix+2 nixos/modules/module-list.nix+1 nixos/modules/services/games/terraria.nix+139 pkgs/games/terraria-server/default.nix+1
nixos/modules/misc/ids.nix+2
@@ -273,6 +273,7 @@
273273 smokeping = 250;
274274 gocd-agent = 251;
275275 gocd-server = 252;
276+ terraria = 253;
276277
277278 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
278279
@@ -516,6 +517,7 @@
516517 smokeping = 250;
517518 gocd-agent = 251;
518519 gocd-server = 252;
520+ terraria = 253;
519521
520522 # When adding a gid, make sure it doesn't match an existing
521523 # uid. Users and groups with the same name should have equal
nixos/modules/module-list.nix+1
@@ -174,6 +174,7 @@
174174 ./services/games/ghost-one.nix
175175 ./services/games/minecraft-server.nix
176176 ./services/games/minetest-server.nix
177+ ./services/games/terraria.nix
177178 ./services/hardware/acpid.nix
178179 ./services/hardware/actkbd.nix
179180 ./services/hardware/amd-hybrid-graphics.nix
nixos/modules/services/games/terraria.nixnew file+139
@@ -0,0 +1,139 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.terraria;
7+ worldSizeMap = { "small" = 1; "medium" = 2; "large" = 3; };
8+ valFlag = name: val: optionalString (val != null) "-${name} \"${escape ["\\" "\""] (toString val)}\"";
9+ boolFlag = name: val: optionalString val "-${name}";
10+ flags = [
11+ (valFlag "port" cfg.port)
12+ (valFlag "maxPlayers" cfg.maxPlayers)
13+ (valFlag "password" cfg.password)
14+ (valFlag "motd" cfg.messageOfTheDay)
15+ (valFlag "world" cfg.worldPath)
16+ (valFlag "autocreate" (builtins.getAttr cfg.autoCreatedWorldSize worldSizeMap))
17+ (valFlag "banlist" cfg.banListPath)
18+ (boolFlag "secure" cfg.secure)
19+ (boolFlag "noupnp" cfg.noUPnP)
20+ ];
21+in
22+{
23+ options = {
24+ services.terraria = {
25+ enable = mkOption {
26+ type = types.bool;
27+ default = false;
28+ description = ''
29+ If enabled, starts a Terraria server. The server can be connected to via <literal>tmux -S /var/lib/terraria/terraria.sock attach</literal>
30+ for administration by users who are a part of the <literal>terraria</literal> group (use <literal>C-b d</literal> shortcut to detach again).
31+ '';
32+ };
33+
34+ port = mkOption {
35+ type = types.int;
36+ default = 7777;
37+ description = ''
38+ Specifies the port to listen on.
39+ '';
40+ };
41+
42+ maxPlayers = mkOption {
43+ type = types.int;
44+ default = 255;
45+ description = ''
46+ Sets the max number of players (between 1 and 255).
47+ '';
48+ };
49+
50+ password = mkOption {
51+ type = types.nullOr types.str;
52+ default = null;
53+ description = ''
54+ Sets the server password. Leave <literal>null</literal> for no password.
55+ '';
56+ };
57+
58+ messageOfTheDay = mkOption {
59+ type = types.nullOr types.str;
60+ default = null;
61+ description = ''
62+ Set the server message of the day text.
63+ '';
64+ };
65+
66+ worldPath = mkOption {
67+ type = types.path;
68+ default = null;
69+ description = ''
70+ The path to the world file (<literal>.wld</literal>) which should be loaded.
71+ If no world exists at this path, one will be created with the size
72+ specified by <literal>autoCreatedWorldSize</literal>.
73+ '';
74+ };
75+
76+ autoCreatedWorldSize = mkOption {
77+ type = types.enum [ "small" "medium" "large" ];
78+ default = "medium";
79+ description = ''
80+ Specifies the size of the auto-created world if <literal>worldPath</literal> does not
81+ point to an existing world.
82+ '';
83+ };
84+
85+ banListPath = mkOption {
86+ type = types.nullOr types.path;
87+ default = null;
88+ description = ''
89+ The path to the ban list.
90+ '';
91+ };
92+
93+ secure = mkOption {
94+ type = types.bool;
95+ default = false;
96+ description = "Adds additional cheat protection to the server.";
97+ };
98+
99+ noUPnP = mkOption {
100+ type = types.bool;
101+ default = false;
102+ description = "Disables automatic Universal Plug and Play.";
103+ };
104+ };
105+ };
106+
107+ config = mkIf cfg.enable {
108+ users.extraUsers.terraria = {
109+ description = "Terraria server service user";
110+ home = "/var/lib/terraria";
111+ createHome = true;
112+ uid = config.ids.uids.terraria;
113+ };
114+
115+ users.extraGroups.terraria = {
116+ gid = config.ids.gids.terraria;
117+ members = [ "terraria" ];
118+ };
119+
120+ systemd.services.terraria = {
121+ description = "Terraria Server Service";
122+ wantedBy = [ "multi-user.target" ];
123+ after = [ "network.target" ];
124+
125+ serviceConfig = {
126+ User = "terraria";
127+ Type = "oneshot";
128+ RemainAfterExit = true;
129+ ExecStart = "${pkgs.tmux.bin}/bin/tmux -S /var/lib/terraria/terraria.sock new -d ${pkgs.terraria-server}/bin/TerrariaServer ${concatStringsSep " " flags}";
130+ ExecStop = "${pkgs.tmux.bin}/bin/tmux -S /var/lib/terraria/terraria.sock send-keys Enter \"exit\" Enter";
131+ };
132+
133+ postStart = ''
134+ ${pkgs.coreutils}/bin/chmod 660 /var/lib/terraria/terraria.sock
135+ ${pkgs.coreutils}/bin/chgrp terraria /var/lib/terraria/terraria.sock
136+ '';
137+ };
138+ };
139+}
pkgs/games/terraria-server/default.nix+1
@@ -16,6 +16,7 @@ stdenv.mkDerivation rec {
1616 installPhase = ''
1717 mkdir -p $out/bin
1818 cp -r Linux $out/
19+ chmod +x "$out/Linux/TerrariaServer.bin.x86_64"
1920 ln -s "$out/Linux/TerrariaServer.bin.x86_64" $out/bin/TerrariaServer
2021 # Fix "/lib64/ld-linux-x86-64.so.2" like references in ELF executables.
2122 find "$out" | while read filepath; do