NixOS/system/podman/valheim.nix

123 lines
3.4 KiB
Nix
Raw Normal View History

2024-10-11 19:39:07 +07:00
{ config, lib, ... }:
2024-09-08 19:42:57 +07:00
let
name = "valheim";
podman = config.profile.podman;
inherit (lib) mkIf strings;
ip = "10.88.200.10";
2024-10-11 19:39:07 +07:00
ip-hutasuhut = "10.88.200.11";
2024-09-08 19:42:57 +07:00
image = "docker.io/lloesche/valheim-server";
domain = "${name}.tigor.web.id";
user = config.profile.user;
uid = toString user.uid;
gid = toString user.gid;
base_dir = "/var/lib/${name}";
2024-10-11 19:39:07 +07:00
base_dir_hutasuhut = "/var/lib/${name}_hutasuhut";
2024-09-08 19:42:57 +07:00
in
2024-10-11 10:01:12 +07:00
lib.mkMerge [
(mkIf (podman.${name}.enable) {
2024-09-08 19:42:57 +07:00
services.caddy.virtualHosts.${domain}.extraConfig = ''
reverse_proxy ${ip}:80
'';
sops =
let
opts = {
sopsFile = ../../secrets/valheim.yaml;
};
2024-09-08 19:42:57 +07:00
in
{
secrets = {
"valheim/server/password" = opts;
"valheim/admins/admin_1" = opts;
"valheim/admins/admin_2" = opts;
"valheim/admins/admin_3" = opts;
};
templates."valheim-env".content =
let
placeholder = config.sops.placeholder;
in
# sh
''
2024-09-08 19:42:57 +07:00
SERVER_PASS=${placeholder."valheim/server/password"}
ADMINLIST_IDS=${placeholder."valheim/admins/admin_1"} ${placeholder."valheim/admins/admin_2"} ${
placeholder."valheim/admins/admin_3"
}
2024-09-08 19:42:57 +07:00
'';
};
2024-10-11 19:39:07 +07:00
systemd.tmpfiles.settings."podman-${name}" = {
${base_dir}.d = {
group = config.profile.user.name;
mode = "0755";
user = config.profile.user.name;
};
2024-09-08 19:42:57 +07:00
};
2024-10-21 14:19:18 +07:00
# systemd.tmpfiles.settings."podman-${name}-hutasuhut" = {
# ${base_dir_hutasuhut}.d = {
# group = config.profile.user.name;
# mode = "0755";
# user = config.profile.user.name;
# };
# };
2024-10-11 19:39:07 +07:00
virtualisation.oci-containers.containers.${name} = {
inherit image;
hostname = name;
autoStart = true;
ports = [ "2456:2456/udp" ];
volumes = [
"${base_dir}/config:/config"
"${base_dir}/data:/opt/valheim"
];
environment = {
TZ = "Asia/Jakarta";
SERVER_NAME = "Three Musketeers";
WORLD_NAME = "Bebas";
STATUS_HTTP = "true";
PUID = uid;
PGID = gid;
2024-09-08 19:42:57 +07:00
};
extraOptions = [
"--network=podman"
"--ip=${ip}"
"--cap-add=sys_nice"
];
environmentFiles = [ config.sops.templates."valheim-env".path ];
labels = {
"io.containers.autoupdate" = "registry";
};
};
2024-10-21 14:19:18 +07:00
# virtualisation.oci-containers.containers."${name}-hutasuhut" = {
# inherit image;
# hostname = name;
# autoStart = true;
# ports = [ "2457:2457/udp" ];
# volumes = [
# "${base_dir_hutasuhut}/config:/config"
# "${base_dir_hutasuhut}/data:/opt/valheim"
# ];
# environment = {
# TZ = "Asia/Jakarta";
# SERVER_NAME = "Hutasuhut";
# WORLD_NAME = "Hutasuhut";
# STATUS_HTTP = "true";
# PUID = uid;
# PGID = gid;
# };
# extraOptions = [
# "--network=podman"
# "--ip=${ip-hutasuhut}"
# "--cap-add=sys_nice"
# ];
# environmentFiles = [ config.sops.templates."valheim-env".path ];
# labels = {
# "io.containers.autoupdate" = "registry";
# };
# };
2024-10-11 10:01:12 +07:00
})
2024-10-21 14:19:18 +07:00
{ profile.services.ntfy-sh.client.settings.subscribe = [{ topic = "valheim"; }]; }
# { profile.services.ntfy-sh.client.settings.subscribe = [{ topic = "valheim-hutasuhut"; }]; }
2024-10-11 10:01:12 +07:00
]