[module/7-days-to-die] Experiment with game server
This commit is contained in:
parent
297d23253e
commit
42c46143df
|
@ -352,7 +352,7 @@
|
|||
writeScriptBin "option" ''
|
||||
host=$1
|
||||
option=$2
|
||||
nix eval .#nixosConfigurations.$host.config.$option 2>/dev/null
|
||||
nix eval .#nixosConfigurations.$host.config.$option
|
||||
'')
|
||||
(with pkgs;
|
||||
writeScriptBin "hm-option" ''
|
||||
|
|
67
modules/7-days-to-die.nix
Normal file
67
modules/7-days-to-die.nix
Normal file
|
@ -0,0 +1,67 @@
|
|||
{ pkgs, 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/"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
{ pkgs, config, ... }:
|
||||
|
||||
{
|
||||
imports = [ ./photoprism.nix ];
|
||||
imports = [ ./photoprism.nix ./7-days-to-die.nix ];
|
||||
|
||||
config = {
|
||||
# Allow joypixels' license and unfree licenses in general
|
||||
|
|
Loading…
Reference in a new issue