nixos/modules/7-days-to-die.nix

69 lines
1.9 KiB
Nix

{
lib,
config,
...
}: let
ports = {
tcp = [26900];
udp = [26900 26901 26902];
};
uid = 459;
gid = 459;
cfg = config.services."7-days-to-die";
portsTcp = map (port: let
portStr = builtins.toString port;
in "${portStr}:${portStr}/tcp");
portsUdp = map (port: let
portStr = builtins.toString port;
in "${portStr}:${portStr}/udp");
in {
options.services."7-days-to-die" = with lib; {
enable = mkEnableOption "7 Days to die game server service";
rootDir = mkOption {
type = types.str;
description = "Path to use for storage";
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = "Whether to open the firewall for ports ${builtins.toString ports}";
};
};
config = lib.mkIf cfg.enable {
# Create the necessary user and group
users = {
groups.sdtd.gid = gid;
users.sdtd = {
inherit uid;
group = config.users.groups.sdtd.name;
isSystemUser = true;
};
};
# Open the port in the firewall if requested
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall ports.tcp;
networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall ports.udp;
virtualisation.oci-containers.containers."7-days-to-die" = {
image = "vinanrra/7dtd-server:latest";
ports = (portsTcp ports.tcp) ++ (portsUdp ports.udp);
environment = {
START_MODE = "1";
PUID = builtins.toString uid;
PGID = builtins.toString gid;
TimeZone = config.time.timeZone;
BACKUP = "NO";
};
volumes = [
"${cfg.rootDir}/saves:/home/sdtdserver/.local/share/7DaysToDie/"
"${cfg.rootDir}/config:/home/sdtdserver/serverfiles/"
"${cfg.rootDir}/logs:/home/sdtdserver/log/"
"${cfg.rootDir}/backups:/home/sdtdserver/lgsm/backup/"
"${cfg.rootDir}/lgsm-config:/home/sdtdserver/lgsm/lgsm-config/sdtdserver/"
];
};
};
}