summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-10-26 16:07:15 -0400
committerKjetil Orbekk <kj@orbekk.com>2022-10-26 16:07:15 -0400
commit24095fd99ab4f9428b86445c2045f066195124ad (patch)
tree9df2f336ecea29f08ab9a52f1bbf65ecdc8f9b8a
parenta5829fdeb5240293063b82af0215ab3b5e13c2c6 (diff)
Zomboid server
-rw-r--r--config/router.nix3
-rw-r--r--machines/dragon.nix1
-rw-r--r--machines/x1-pincer.nix2
-rw-r--r--modules/gaming.nix8
-rw-r--r--modules/valheim.nix69
-rw-r--r--modules/zomboid.nix55
6 files changed, 68 insertions, 70 deletions
diff --git a/config/router.nix b/config/router.nix
index 7426235..4a503aa 100644
--- a/config/router.nix
+++ b/config/router.nix
@@ -129,6 +129,9 @@ in {
proto tcp dport (139 445) ACCEPT;
proto udp dport (137 138) ACCEPT;
+ # Project Zomboid
+ proto udp dport (16261 16262) ACCEPT;
+
# interface $DEV_LAN jump logdrop;
}
}
diff --git a/machines/dragon.nix b/machines/dragon.nix
index 79c7d42..547532b 100644
--- a/machines/dragon.nix
+++ b/machines/dragon.nix
@@ -17,6 +17,7 @@ in {
orbekk.backups.enableClient = true;
orbekk.vpn.enable = true;
orbekk.bridge.enable = true;
+ orbekk.zomboid-server.enable = true;
environment.systemPackages = with pkgs; [ ipmitool ];
programs.mosh.enable = true;
diff --git a/machines/x1-pincer.nix b/machines/x1-pincer.nix
index 210deda..b99c4ae 100644
--- a/machines/x1-pincer.nix
+++ b/machines/x1-pincer.nix
@@ -13,6 +13,8 @@ let ports = {
orbekk.thinkpad.enable = true;
orbekk.simple-firewall.allowedTCPPorts = [ ports.minecraft 631 5353 ]; # socks proxy
+ orbekk.zomboid-server.enable = true;
+
orbekk.vpn.enable = true;
services.printing.enable = true;
diff --git a/modules/gaming.nix b/modules/gaming.nix
index 61b089b..dc881d7 100644
--- a/modules/gaming.nix
+++ b/modules/gaming.nix
@@ -198,7 +198,13 @@ in {
# nixpkgs.config.allowBroken = true;
nixpkgs.config.allowUnfreePredicate = pkg:
- builtins.elem (lib.getName pkg) [ "steam" "steam-original" "steam-runtime" "minecraft-launcher" ];
+ builtins.elem (lib.getName pkg) [
+ "steam"
+ "steamcmd"
+ "steam-original"
+ "steam-runtime"
+ "minecraft-launcher"
+ ];
services.flatpak.enable = true;
diff --git a/modules/valheim.nix b/modules/valheim.nix
deleted file mode 100644
index f12a894..0000000
--- a/modules/valheim.nix
+++ /dev/null
@@ -1,69 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-let
- cfg = config.orbekk.valheim-server;
- statePath = "/var/lib/${cfg.stateDir}";
-in
-{
- options = {
- orbekk.valheim-server = {
- enable = lib.mkEnableOption "Enable valheim server";
- programDir = lib.mkOption {
- type = lib.types.str;
- default = null;
- };
- stateDir = lib.mkOption {
- type = lib.types.str;
- default = "valheim";
- };
- statusPort = lib.mkOption {
- type = lib.types.int;
- default = 12817;
- };
- };
- };
-
- config = lib.mkIf cfg.enable {
- systemd.services.valheim-server = {
- description = "Valheim server";
- wantedBy = [ "multi-user.target" ];
- after = [ "network.target" ];
- path = with pkgs; [ steam.run ];
-
- serviceConfig = {
- DynamicUser = true;
- StateDirectory = cfg.stateDir;
- KillSignal = "SIGINT";
- };
-
- environment = {
- HOME = statePath;
- };
-
- script = ''
- cd ${cfg.programDir}
- export templdpath=$LD_LIBRARY_PATH
- export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH
- export SteamAppId=892970
- steam-run ./valheim_server.x86_64 -name "doomsday" -port 3400 -world "doomsday" -password "$(cat ${statePath}/password.txt)" -savedir ${statePath} -nographics -batchmode
- '';
- };
-
- systemd.services.valheim-server-prober = {
- description = "Collect metrics for valheim-server";
- startAt = "*:0/5";
- path = with pkgs; [ moreutils systemd gnugrep coreutils ];
- script = ''
- systemctl show valheim-server | \
- grep -E 'IPIngress|IPEgress|CPUUsage' | \
- tr '=' ' ' | {
- while read k v; do
- echo "# TYPE $k counter"
- echo "systemd_$k{unit=\"valheim-server.service\"} $v";
- done
- } | \
- sponge ${config.orbekk.monitoring-server.textFileDir}/valheim_server.prom
- '';
- };
- };
-}
diff --git a/modules/zomboid.nix b/modules/zomboid.nix
new file mode 100644
index 0000000..3f5dd37
--- /dev/null
+++ b/modules/zomboid.nix
@@ -0,0 +1,55 @@
+{ config, lib, pkgs, ... }:
+
+let
+ cfg = config.orbekk.zomboid-server;
+ statePath = "/var/lib/${cfg.stateDir}";
+ update-zomboid = pkgs.writeText "update-zomboid" ''
+ // update_zomboid.txt
+ @ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once
+ @NoPromptForPassword 1
+ //force_install_dir /opt/pzserver/
+ //for servers which don't need a login
+ login anonymous
+ // app_update 380870 validate
+ app_update 380870
+ quit
+ '';
+in
+{
+ options = {
+ orbekk.zomboid-server = {
+ enable = lib.mkEnableOption "Enable zomboid server";
+ stateDir = lib.mkOption {
+ type = lib.types.str;
+ default = "zomboid";
+ };
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ systemd.services.zomboid-server = {
+ description = "Zomboid server";
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" ];
+ path = with pkgs; [ steam.run ];
+
+ serviceConfig = {
+ DynamicUser = true;
+ StateDirectory = cfg.stateDir;
+ CacheDirectory = cfg.stateDir;
+ LogsDirectory = cfg.stateDir;
+ RuntimeDirectory = cfg.stateDir;
+ };
+
+ environment = {
+ HOME = statePath;
+ };
+
+ script = ''
+ ${pkgs.steamcmd}/bin/steamcmd +runscript ${update-zomboid}
+ cd $HOME/.local/share/Steam/Steamapps/common/Project\ Zomboid\ Dedicated\ Server
+ ${pkgs.steam.run}/bin/steam-run ./start-server.sh -adminpassword changeme -ip 0.0.0.0 -cachedir=${statePath}/Zomboid
+ '';
+ };
+ };
+}