config valheim

This commit is contained in:
2026-09-10 12:34:47 -05:00
parent c9dc8a0def
commit 60e745a3d9
+21 -35
View File
@@ -16,7 +16,7 @@ in {
# set port options # set port options
port = lib.mkOption { port = lib.mkOption {
type = lib.types.int; type = lib.types.int;
default = 7704; default = 2456;
description = "set port for ${service} (default: ${toString cfg.port}"; description = "set port for ${service} (default: ${toString cfg.port}";
}; };
url = lib.mkOption { url = lib.mkOption {
@@ -26,7 +26,7 @@ in {
}; };
data_dir = lib.mkOption { data_dir = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "/var/lib/${service}"; default = "/var/lib/gameservers/${service}";
description = "set data directory for ${service}"; description = "set data directory for ${service}";
}; };
ids = lib.mkOption { ids = lib.mkOption {
@@ -34,15 +34,15 @@ in {
default = cfg.port; default = cfg.port;
description = "set uid and pid of ${service} user (matches port by default)"; description = "set uid and pid of ${service} user (matches port by default)";
}; };
motd_gs = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = ["podman-valheim"];
};
backup = lib.mkOption { backup = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = false; default = false;
description = "enable backups for ${service}"; description = "enable backups for ${service}";
}; };
motd_gs = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = ["craftoria"];
};
backup_repo = lib.mkOption { backup_repo = lib.mkOption {
type = lib.types.path; type = lib.types.path;
default = "/var/backup/gameservers/valheim"; default = "/var/backup/gameservers/valheim";
@@ -81,17 +81,24 @@ in {
}; };
virtualisation.oci-containers.containers = { virtualisation.oci-containers.containers = {
hass = { ${service} = {
image = "homeassistant/home-assistant:stable"; image = "ghcr.io/community-valheim-tools/valheim-server";
autoStart = true; autoStart = true;
extraOptions = [ extraOptions = [
"--pull=newer" "--cap-add=sys_nice"
"--network=host" "--stop-timeout=120"
];
ports = [
"2456-2457:2456-2457/udp"
]; ];
volumes = [ volumes = [
"${cfg.data_dir}:/config" "${cfg.data_dir}/config:/config"
"${cfg.data_dir}/data:/opt/valheim"
]; ];
environment = { environment = {
SERVER_NAME = "recpro";
SERVER_PASS = "recoil727pro";
WORLD_NAME = "";
TZ = homelab.tz; TZ = homelab.tz;
PUID = toString config.users.users.${service}.uid; PUID = toString config.users.users.${service}.uid;
PGID = toString config.users.groups.${service}.gid; PGID = toString config.users.groups.${service}.gid;
@@ -105,35 +112,14 @@ in {
}; };
# open firewall # open firewall
networking.firewall.allowedTCPPorts = [cfg.port 8123 21063 21064]; # networking.firewall.allowedTCPPorts = [cfg.port];
networking.firewall.allowedUDPPorts = [5353]; networking.firewall.allowedUDPPorts = [2456 2457];
# add to caddy for reverse proxy
services.caddy.virtualHosts."${cfg.url}" = {
serverAliases = ["${service}.${homelab.public_domain}"];
extraConfig = ''
tls internal
reverse_proxy 127.0.0.1:${toString cfg.port} {
}
'';
};
# backups valhiem with borg! # backups valhiem with borg!
services.borgbackup.jobs.${service} = { services.borgbackup.jobs.${service} = {
archiveBaseName = service; archiveBaseName = service;
repo = cfg.backup_repo; repo = cfg.backup_repo;
paths = lib.flatten ( paths = cfg.data_dir;
lib.attrValues (
lib.mapAttrs (_: srv:
[srv.data_dir]
++ (
if builtins.hasAttr "db_dump" srv
then [srv.db_dump]
else []
))
servers
)
);
compression = "auto,zstd"; compression = "auto,zstd";
#preHook = "systemctl start mysql-backup.service"; #preHook = "systemctl start mysql-backup.service";
postHook = '' postHook = ''