clean up glance and try and add minecraft monitor

This commit is contained in:
2025-10-12 14:55:09 -05:00
parent 2cc42a5800
commit 394d12a7b2
7 changed files with 300 additions and 318 deletions

View File

@@ -1,6 +1,6 @@
# flake for blakes nixos config # flake for blakes nixos config
# define new devices in outputs # define new devices in outputs
# generation: 363, timestamp: 2025-10-12 14:16:09 # generation: 364, timestamp: 2025-10-12 14:54:50
{ {
description = "blakes nix config"; description = "blakes nix config";
inputs = { inputs = {

View File

@@ -98,7 +98,7 @@ in
}; };
pages = [ pages = [
{ {
name = "violet"; name = "snowbelle";
hide-desktop-navigation = true; hide-desktop-navigation = true;
columns = [ columns = [
{ {
@@ -136,46 +136,30 @@ in
cache = "1m"; cache = "1m";
title = "services"; title = "services";
sites = cfg.links.services; sites = cfg.links.services;
# sites = [
# { title = "jellyfin"; url = "https://media.blakedheld.xyz"; icon = "di:jellyfin"; }
# { title = "audiobookshelf"; url = "https://audiobooks.blakedheld.xyz"; icon = "di:audiobookshelf"; }
# { title = "yacreader"; url = "http://10.10.0.30:3434"; icon = "/assets/icons/yacreader.png"; }
# { title = "sonarr"; url = "http://10.10.0.30:3636"; icon = "di:sonarr"; }
# { title = "qbittorrent"; url = "http://10.10.0.40:3333"; icon = "di:qbittorrent"; }
# { title = "radarr"; url = "http://10.10.0.30:3737"; icon = "di:radarr"; }
# { title = "kiwix"; url = "http://10.10.0.30:5050"; icon = "di:kiwix"; }
# { title = "prowlarr"; url = "http://10.10.0.30:3535"; icon = "di:prowlarr"; }
# { title = "bazarr"; url = "http://10.10.0.30:3838"; icon = "di:bazarr"; }
# ];
} }
{ {
type = "monitor"; type = "monitor";
cache = "1m"; cache = "1m";
title = "mediastack"; title = "mediastack";
sites = cfg.links.mediastack; sites = cfg.links.mediastack;
# [
# { title = "immich"; url = "https://pics.blakedheld.xyz"; icon = "di:immich"; }
# { title = "vaultwarden"; url = "https://pass.blakedheld.xyz"; icon = "di:vaultwarden"; }
# { title = "gitea"; url = "https://git.blakedheld.xyz"; icon = "di:gitea"; }
# { title = "home assistant"; url = "https://home.blakedheld.xyz"; icon = "di:home-assistant"; }
# { title = "zigbee2mqtt"; url = "http://10.10.0.30:4142"; icon = "di:zigbee2mqtt"; }
# { title = "syncthing"; url = "http://10.10.0.20:2222"; icon = "di:syncthing"; }
# { title = "archivebox"; url = "http://10.10.0.30:5656"; icon = "sh:archivebox"; }
# { title = "copyparty"; url = "http://10.10.0.20:3923"; icon = "sh:copyparty"; }
# ];
} }
{ {
type = "monitor"; type = "monitor";
cache = "1m"; cache = "1m";
title = "system"; title = "system";
sites = cfg.links.system; sites = cfg.links.system;
# [ }
# { title = "proxmox"; url = "http://10.10.0.10:8006"; icon = "di:proxmox"; allow-insecure = true; } {
# { title = "nginx"; url = "http://10.10.0.30:8080"; icon = "di:nginx"; } type = "custom-api";
# { title = "uptime kuma"; url = "http://10.10.0.30:8181"; icon = "di:uptime-kuma"; } title = "minecraft recpro";
# { title = "tn holocron"; url = "https://10.10.0.20"; icon = "di:truenas"; allow-insecure = true; } cache = "5s";
# { title = "bebe"; url = "https://10.10.0.1"; icon = "di:unifi"; allow-insecure = true; } allow-insecure = true;
# ]; url = "\${CRAFTY_URL}/api/v2/servers/\${CRAFTY_SERVER_ID}/stats";
headers = {
Authorization = "Bearer \${CRAFTY_API_TOKEN}";
Accept = "application/json";
};
template = "<!-- USER SETTINGS SECTION -->\n\n<!-- Change true to false if you wish to not display the MOTD -->\n{{ $displayMOTD := true }}\n\n<!-- END OF USER SETTINGS SECTION -->\n\n{{ $is_running := .JSON.Bool \"data.running\" }}\n{{ $online_players := .JSON.Int \"data.online\" | formatNumber }}\n{{ $max_players := .JSON.Int \"data.max\" | formatNumber }}\n{{ $name := .JSON.String \"data.world_name\" }}\n{{ $size := .JSON.String \"data.world_size\" }}\n{{ $version := .JSON.String \"data.version\" }}\n{{ $icon := .JSON.String \"data.icon\" }}\n{{ $server_ip := .JSON.String \"data.server_id.server_ip\" }}\n{{ $server_port := .JSON.String \"data.server_id.server_port\" }}\n{{ $motd := .JSON.String \"data.desc\" }}\n\n{{ $server_addr := \"\" }}\n{{ if and ($is_running) (eq $server_ip \"127.0.0.1\") }}\n {{ $server_addr = printf \"%s:%s\" (replaceMatches \"https?://\" \"\" \"\${CRAFTY_URL}\") $server_port }}\n{{ else if $is_running }}\n {{ $server_addr = printf \"%s:%s\" $server_ip $server_port }}\n{{ end }}\n\n{{ $starting := false }}\n{{ if and ($is_running) (eq $max_players \"0\") (eq $version \"False\") }}\n {{ $starting = true }}\n{{ end }}\n\n<!-- I couldn't find documentation describing the \"waiting_start\" state or the other booleans below. Implementation might not be correct. -->\n{{ $updating := .JSON.Bool \"data.updating\" }}\n{{ $importing := .JSON.Bool \"data.importing\" }}\n{{ $crashed := .JSON.Bool \"data.crashed\" }}\n\n<div style=\"display:flex; align-items:center; gap:12px;\">\n <!-- Server Icon -->\n <div style=\"width:40px; height:40px; flex-shrink:0; border-radius:4px; display:flex; justify-content:center; align-items:center; overflow:hidden;\">\n {{ if eq $icon \"\" }}\n <img src=\"https://cdn.jsdelivr.net/gh/selfhst/icons/png/minecraft.png\" style=\"width:100%; height:100%; object-fit:contain;\" alt=\"Server icon\">\n {{ else }}\n <img src=\"data:image/png;base64, {{ $icon }}\" style=\"width:100%; height:100%; object-fit:contain;\" alt=\"Server icon\">\n {{ end }}\n </div>\n\n <!-- Right side: Info -->\n <div style=\"display:flex; flex-direction:column;\">\n <!-- First row: Server Name + IP -->\n <div style=\"display:flex; align-items:center; gap:6px;\">\n <span class=\"size-h4 block text-truncate color-primary\">\n {{ $name }}\n </span>\n\n {{ if and ($is_running) (not $starting) (not (eq $server_addr \"\")) }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">\n <span class=\"size-h6 color-secondary\">\n {{ $server_addr }}\n </span>\n </div>\n {{ end }}\n </div>\n\n <!-- Second row: MOTD & Stats if server is running, otherwise show status msg ... -->\n {{ if and ($is_running) (not $starting) }}\n {{ if and (not (eq $motd \"\")) ($displayMOTD) }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">\n {{ replaceMatches \"§.\" \"\" $motd }}\n </div>\n {{ end }}\n\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">\n {{ $version }} - {{ $online_players }}/{{ $max_players }} players - {{ $size }}\n </div>\n\n <!-- lots of assumptions about the boolean states meanings from crafty api.. -->\n {{ else if $starting }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is starting up..</div>\n {{ else if $importing }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is being imported..</div>\n {{ else if $updating }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is being updated..</div>\n {{ else if $crashed }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server has crashed!</div>\n {{ else }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is offline</div>\n {{ end }}\n </div>\n</div>";
} }
]; ];
} }

View File

@@ -1,5 +1,21 @@
{ pkgs, config, lib, ... }: { pkgs, config, lib, ... }:
/*
this is a wrapper module for glance that allows you to
to pass monitor entries in with nix, all declaratively!
| <8yy> |
V V
# add to glance
modules.services.glance.links.mediastack = [{
title = service;
url = "https://${cfg.url}";
error-url = "http://${homelab.host_ip}:${toString cfg.port}";
check-url = "http://${homelab.host_ip}:${toString cfg.port}";
icon = "di:${service}";
allow-insecure = true; }];
*/
let let
service = "glance"; service = "glance";
cfg = config.modules.services.${service}; cfg = config.modules.services.${service};
@@ -36,20 +52,28 @@ in
default = true; default = true;
description = "enable backups for ${service}"; description = "enable backups for ${service}";
}; };
pages = lib.mkOption { links = {
type = lib.types.attrsOf (lib.types.submodule { services = lib.mkOption {
options.description = lib.mkOption { type = lib.types.str; }; type = lib.types.listOf lib.types.attrs;
options.url = lib.mkOption { type = lib.types.str; }; default = [];
options.icon = lib.mkOption { type = lib.types.str; }; description = "list of links for ${service}";
options.category = lib.mkOption { type = lib.types.str; }; };
}); mediastack = lib.mkOption {
default = {}; type = lib.types.listOf lib.types.attrs;
description = "configure the service for use in ${service}"; default = [];
description = "list of links for ${service}";
};
system = lib.mkOption {
type = lib.types.listOf lib.types.attrs;
default = [];
description = "list of links for ${service}";
};
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
# declare ${service} group # declare ${service} group
users.groups.${service} = { gid = lib.mkForce cfg.ids; }; users.groups.${service} = { gid = lib.mkForce cfg.ids; };
@@ -110,45 +134,48 @@ in
{ {
type = "monitor"; type = "monitor";
cache = "1m"; cache = "1m";
title = "mediastack"; title = "services";
sites = [ sites = cfg.links.services;
{ title = "jellyfin"; url = "https://media.blakedheld.xyz"; icon = "di:jellyfin"; } # sites = [
{ title = "audiobookshelf"; url = "https://audiobooks.blakedheld.xyz"; icon = "di:audiobookshelf"; } # { title = "jellyfin"; url = "https://media.blakedheld.xyz"; icon = "di:jellyfin"; }
{ title = "yacreader"; url = "http://10.10.0.30:3434"; icon = "/assets/icons/yacreader.png"; } # { title = "audiobookshelf"; url = "https://audiobooks.blakedheld.xyz"; icon = "di:audiobookshelf"; }
{ title = "sonarr"; url = "http://10.10.0.30:3636"; icon = "di:sonarr"; } # { title = "yacreader"; url = "http://10.10.0.30:3434"; icon = "/assets/icons/yacreader.png"; }
{ title = "qbittorrent"; url = "http://10.10.0.40:3333"; icon = "di:qbittorrent"; } # { title = "sonarr"; url = "http://10.10.0.30:3636"; icon = "di:sonarr"; }
{ title = "radarr"; url = "http://10.10.0.30:3737"; icon = "di:radarr"; } # { title = "qbittorrent"; url = "http://10.10.0.40:3333"; icon = "di:qbittorrent"; }
{ title = "kiwix"; url = "http://10.10.0.30:5050"; icon = "di:kiwix"; } # { title = "radarr"; url = "http://10.10.0.30:3737"; icon = "di:radarr"; }
{ title = "prowlarr"; url = "http://10.10.0.30:3535"; icon = "di:prowlarr"; } # { title = "kiwix"; url = "http://10.10.0.30:5050"; icon = "di:kiwix"; }
{ title = "bazarr"; url = "http://10.10.0.30:3838"; icon = "di:bazarr"; } # { title = "prowlarr"; url = "http://10.10.0.30:3535"; icon = "di:prowlarr"; }
]; # { title = "bazarr"; url = "http://10.10.0.30:3838"; icon = "di:bazarr"; }
# ];
} }
{ {
type = "monitor"; type = "monitor";
cache = "1m"; cache = "1m";
title = "services"; title = "mediastack";
sites = [ sites = cfg.links.mediastack;
{ title = "immich"; url = "https://pics.blakedheld.xyz"; icon = "di:immich"; } # [
{ title = "vaultwarden"; url = "https://pass.blakedheld.xyz"; icon = "di:vaultwarden"; } # { title = "immich"; url = "https://pics.blakedheld.xyz"; icon = "di:immich"; }
{ title = "gitea"; url = "https://git.blakedheld.xyz"; icon = "di:gitea"; } # { title = "vaultwarden"; url = "https://pass.blakedheld.xyz"; icon = "di:vaultwarden"; }
{ title = "home assistant"; url = "https://home.blakedheld.xyz"; icon = "di:home-assistant"; } # { title = "gitea"; url = "https://git.blakedheld.xyz"; icon = "di:gitea"; }
{ title = "zigbee2mqtt"; url = "http://10.10.0.30:4142"; icon = "di:zigbee2mqtt"; } # { title = "home assistant"; url = "https://home.blakedheld.xyz"; icon = "di:home-assistant"; }
{ title = "syncthing"; url = "http://10.10.0.20:2222"; icon = "di:syncthing"; } # { title = "zigbee2mqtt"; url = "http://10.10.0.30:4142"; icon = "di:zigbee2mqtt"; }
{ title = "archivebox"; url = "http://10.10.0.30:5656"; icon = "sh:archivebox"; } # { title = "syncthing"; url = "http://10.10.0.20:2222"; icon = "di:syncthing"; }
{ title = "copyparty"; url = "http://10.10.0.20:3923"; icon = "sh:copyparty"; } # { title = "archivebox"; url = "http://10.10.0.30:5656"; icon = "sh:archivebox"; }
]; # { title = "copyparty"; url = "http://10.10.0.20:3923"; icon = "sh:copyparty"; }
# ];
} }
{ {
type = "monitor"; type = "monitor";
cache = "1m"; cache = "1m";
title = "system"; title = "system";
sites = [ sites = cfg.links.system;
{ title = "proxmox"; url = "http://10.10.0.10:8006"; icon = "di:proxmox"; allow-insecure = true; } # [
{ title = "nginx"; url = "http://10.10.0.30:8080"; icon = "di:nginx"; } # { title = "proxmox"; url = "http://10.10.0.10:8006"; icon = "di:proxmox"; allow-insecure = true; }
{ title = "uptime kuma"; url = "http://10.10.0.30:8181"; icon = "di:uptime-kuma"; } # { title = "nginx"; url = "http://10.10.0.30:8080"; icon = "di:nginx"; }
{ title = "tn holocron"; url = "https://10.10.0.20"; icon = "di:truenas"; allow-insecure = true; } # { title = "uptime kuma"; url = "http://10.10.0.30:8181"; icon = "di:uptime-kuma"; }
{ title = "bebe"; url = "https://10.10.0.1"; icon = "di:unifi"; allow-insecure = true; } # { title = "tn holocron"; url = "https://10.10.0.20"; icon = "di:truenas"; allow-insecure = true; }
]; # { title = "bebe"; url = "https://10.10.0.1"; icon = "di:unifi"; allow-insecure = true; }
# ];
} }
]; ];
} }
@@ -196,25 +223,6 @@ in
# # open firewall # # open firewall
# networking.firewall.allowedTCPPorts = [ cfg.port ]; # networking.firewall.allowedTCPPorts = [ cfg.port ];
# internal reverse proxy entry
services.nginx.virtualHosts."${cfg.url}" = {
forceSSL = true;
sslCertificate = sec."ssl_blakedheld_crt".path;
sslCertificateKey = sec."ssl_blakedheld_key".path;
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
};
};
# # external reverse proxy entry
# services.nginx.virtualHosts."${service}.blakedheld.xyz" = {
# forceSSL = true;
# sslCertificate = sec."ssl_blakedheld_crt".path;
# sslCertificateKey = sec."ssl_blakedheld_key".path;
# locations."/" = {
# proxyPass = "http://127.0.0.1:${toString cfg.port}";
# };
# };
#
# sops.secrets = { # sops.secrets = {
# "${service}_" = { # "${service}_" = {
# owner = "${service}"; # owner = "${service}";
@@ -222,6 +230,15 @@ in
# }; # };
# }; # };
# add to caddy for reverse proxy
services.caddy.virtualHosts."${cfg.url}" = {
# serverAliases = [ "${homelab.public_domain}" ];
extraConfig = ''
tls ${sec."ssl_blakedheld_crt".path} ${sec."ssl_blakedheld_key".path}
reverse_proxy http://127.0.0.1:${toString cfg.port}
'';
};
# add to backups # add to backups
modules.system.backups.baks = { modules.system.backups.baks = {
${service} = { paths = [ cfg.data_dir ]; }; ${service} = { paths = [ cfg.data_dir ]; };

View File

@@ -1,230 +0,0 @@
{ pkgs, config, lib, ... }:
let
service = "glance";
cfg = config.modules.services.${service};
sec = config.sops.secrets;
homelab = config.modules.homelab;
in
{
options.modules.services.${service} = {
enable = lib.mkEnableOption "enables ${service}";
# set port options
port = lib.mkOption {
type = lib.types.int;
default = 7700;
description = "set port for ${service} (default: ${toString cfg.port}";
};
url = lib.mkOption {
type = lib.types.str;
default = "${homelab.base_domain}";
description = "set domain for ${service}";
};
data_dir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/${service}";
description = "set data directory for ${service}";
};
ids = lib.mkOption {
type = lib.types.int;
default = cfg.port;
description = "set uid and pid of ${service} user (matches port by default)";
};
backup = lib.mkOption {
type = lib.types.bool;
default = true;
description = "enable backups for ${service}";
};
pages = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule {
options.description = lib.mkOption { type = lib.types.str; };
options.url = lib.mkOption { type = lib.types.str; };
options.icon = lib.mkOption { type = lib.types.str; };
options.category = lib.mkOption { type = lib.types.str; };
});
default = {};
description = "configure the service for use in ${service}";
};
};
config = lib.mkIf cfg.enable {
# declare ${service} group
users.groups.${service} = { gid = lib.mkForce cfg.ids; };
# declare ${service} user
users.users.${service} = {
description = "${service} server user";
uid = lib.mkForce cfg.ids;
isSystemUser = true;
home = cfg.data_dir;
createHome = true;
group = "${service}";
extraGroups = [];
};
services.${service} = {
enable = true;
openFirewall = true;
settings = {
server = {
host = "0.0.0.0";
port = cfg.port;
};
pages = [
{
name = "violet";
hide-desktop-navigation = true;
columns = [
{
size = "small";
widgets = [
{ type = "calendar"; first-day-of-week = "monday"; }
{ type = "server-stats"; servers = [ { type = "local"; name = "violet"; } ]; }
{
type = "clock";
hour-format = "24h";
timezones = [
{ timezone = "America/Chicago"; label = "HTX"; }
{ timezone = "America/Denver"; label = "AF"; }
];
}
{ type = "twitch-channels"; channels = [ "mang0" "SaltSSBM" "thewaffle77" "ironmouse" "linustech" ]; }
];
}
{
size = "full";
widgets = [
{
type = "search";
autofocus = true;
search-engine = "https://www.ecosia.org/search?q={QUERY}";
new-tab = true;
bangs = [
{ title = "YouTube"; shortcut = "!y"; url = "https://www.youtube.com/results?search_query={QUERY}"; }
{ title = "Google"; shortcut = "!g"; url = "https://www.google.com/search?q={QUERY}"; }
{ title = "Github"; shortcut = "!gh"; url = "https://github.com/search?q={QUERY}&type=repositories"; }
];
}
{
type = "monitor";
cache = "1m";
title = "mediastack";
sites = [
{ title = "jellyfin"; url = "https://media.blakedheld.xyz"; icon = "di:jellyfin"; }
{ title = "audiobookshelf"; url = "https://audiobooks.blakedheld.xyz"; icon = "di:audiobookshelf"; }
{ title = "yacreader"; url = "http://10.10.0.30:3434"; icon = "/assets/icons/yacreader.png"; }
{ title = "sonarr"; url = "http://10.10.0.30:3636"; icon = "di:sonarr"; }
{ title = "qbittorrent"; url = "http://10.10.0.40:3333"; icon = "di:qbittorrent"; }
{ title = "radarr"; url = "http://10.10.0.30:3737"; icon = "di:radarr"; }
{ title = "kiwix"; url = "http://10.10.0.30:5050"; icon = "di:kiwix"; }
{ title = "prowlarr"; url = "http://10.10.0.30:3535"; icon = "di:prowlarr"; }
{ title = "bazarr"; url = "http://10.10.0.30:3838"; icon = "di:bazarr"; }
];
}
{
type = "monitor";
cache = "1m";
title = "services";
sites = [
{ title = "immich"; url = "https://pics.blakedheld.xyz"; icon = "di:immich"; }
{ title = "vaultwarden"; url = "https://pass.blakedheld.xyz"; icon = "di:vaultwarden"; }
{ title = "gitea"; url = "https://git.blakedheld.xyz"; icon = "di:gitea"; }
{ title = "home assistant"; url = "https://home.blakedheld.xyz"; icon = "di:home-assistant"; }
{ title = "zigbee2mqtt"; url = "http://10.10.0.30:4142"; icon = "di:zigbee2mqtt"; }
{ title = "syncthing"; url = "http://10.10.0.20:2222"; icon = "di:syncthing"; }
{ title = "archivebox"; url = "http://10.10.0.30:5656"; icon = "sh:archivebox"; }
{ title = "copyparty"; url = "http://10.10.0.20:3923"; icon = "sh:copyparty"; }
];
}
{
type = "monitor";
cache = "1m";
title = "system";
sites = [
{ title = "proxmox"; url = "http://10.10.0.10:8006"; icon = "di:proxmox"; allow-insecure = true; }
{ title = "nginx"; url = "http://10.10.0.30:8080"; icon = "di:nginx"; }
{ title = "uptime kuma"; url = "http://10.10.0.30:8181"; icon = "di:uptime-kuma"; }
{ title = "tn holocron"; url = "https://10.10.0.20"; icon = "di:truenas"; allow-insecure = true; }
{ title = "bebe"; url = "https://10.10.0.1"; icon = "di:unifi"; allow-insecure = true; }
];
}
];
}
{
size = "small";
widgets = [
{ type = "weather"; location = "Pearland, Texas, United States"; units = "imperial"; hour-format = "24h"; }
{
type = "markets";
markets = [
{ symbol = "SPY"; name = "S&P 500"; }
{ symbol = "XMR-USD"; name = "Monero"; }
{ symbol = "NVDA"; name = "NVIDIA"; }
{ symbol = "AAPL"; name = "Apple"; }
{ symbol = "MSFT"; name = "Microsoft"; }
];
}
{
type = "releases";
cache = "1d";
repositories = [
"glanceapp/glance"
"go-gitea/gitea"
"immich-app/immich"
"syncthing/syncthing"
];
}
];
}
];
}
];
};
};
# override umask to make permissions work out
systemd.services.${service}.serviceConfig = {
UMask = lib.mkForce "0007";
# User = "${service}";
# Group = "${service}";
};
# # open firewall
# networking.firewall.allowedTCPPorts = [ cfg.port ];
# internal reverse proxy entry
services.nginx.virtualHosts."${cfg.url}" = {
forceSSL = true;
sslCertificate = sec."ssl_blakedheld_crt".path;
sslCertificateKey = sec."ssl_blakedheld_key".path;
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
};
};
# # external reverse proxy entry
# services.nginx.virtualHosts."${service}.blakedheld.xyz" = {
# forceSSL = true;
# sslCertificate = sec."ssl_blakedheld_crt".path;
# sslCertificateKey = sec."ssl_blakedheld_key".path;
# locations."/" = {
# proxyPass = "http://127.0.0.1:${toString cfg.port}";
# };
# };
#
# sops.secrets = {
# "${service}_" = {
# owner = "${service}";
# group = "${service}";
# };
# };
# add to backups
modules.system.backups.baks = {
${service} = { paths = [ cfg.data_dir ]; };
};
};
}

View File

@@ -0,0 +1,14 @@
[
{
type = "custom-api";
title = "Crafty Controller Minecraft Server";
cache = "5s";
allow-insecure = true;
url = "\${CRAFTY_URL}/api/v2/servers/\${CRAFTY_SERVER_ID}/stats";
headers = {
Authorization = "Bearer \${CRAFTY_API_TOKEN}";
Accept = "application/json";
};
template = "<!-- USER SETTINGS SECTION -->\n\n<!-- Change true to false if you wish to not display the MOTD -->\n{{ $displayMOTD := true }}\n\n<!-- END OF USER SETTINGS SECTION -->\n\n{{ $is_running := .JSON.Bool \"data.running\" }}\n{{ $online_players := .JSON.Int \"data.online\" | formatNumber }}\n{{ $max_players := .JSON.Int \"data.max\" | formatNumber }}\n{{ $name := .JSON.String \"data.world_name\" }}\n{{ $size := .JSON.String \"data.world_size\" }}\n{{ $version := .JSON.String \"data.version\" }}\n{{ $icon := .JSON.String \"data.icon\" }}\n{{ $server_ip := .JSON.String \"data.server_id.server_ip\" }}\n{{ $server_port := .JSON.String \"data.server_id.server_port\" }}\n{{ $motd := .JSON.String \"data.desc\" }}\n\n{{ $server_addr := \"\" }}\n{{ if and ($is_running) (eq $server_ip \"127.0.0.1\") }}\n {{ $server_addr = printf \"%s:%s\" (replaceMatches \"https?://\" \"\" \"\${CRAFTY_URL}\") $server_port }}\n{{ else if $is_running }}\n {{ $server_addr = printf \"%s:%s\" $server_ip $server_port }}\n{{ end }}\n\n{{ $starting := false }}\n{{ if and ($is_running) (eq $max_players \"0\") (eq $version \"False\") }}\n {{ $starting = true }}\n{{ end }}\n\n<!-- I couldn't find documentation describing the \"waiting_start\" state or the other booleans below. Implementation might not be correct. -->\n{{ $updating := .JSON.Bool \"data.updating\" }}\n{{ $importing := .JSON.Bool \"data.importing\" }}\n{{ $crashed := .JSON.Bool \"data.crashed\" }}\n\n<div style=\"display:flex; align-items:center; gap:12px;\">\n <!-- Server Icon -->\n <div style=\"width:40px; height:40px; flex-shrink:0; border-radius:4px; display:flex; justify-content:center; align-items:center; overflow:hidden;\">\n {{ if eq $icon \"\" }}\n <img src=\"https://cdn.jsdelivr.net/gh/selfhst/icons/png/minecraft.png\" style=\"width:100%; height:100%; object-fit:contain;\" alt=\"Server icon\">\n {{ else }}\n <img src=\"data:image/png;base64, {{ $icon }}\" style=\"width:100%; height:100%; object-fit:contain;\" alt=\"Server icon\">\n {{ end }}\n </div>\n\n <!-- Right side: Info -->\n <div style=\"display:flex; flex-direction:column;\">\n <!-- First row: Server Name + IP -->\n <div style=\"display:flex; align-items:center; gap:6px;\">\n <span class=\"size-h4 block text-truncate color-primary\">\n {{ $name }}\n </span>\n\n {{ if and ($is_running) (not $starting) (not (eq $server_addr \"\")) }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">\n <span class=\"size-h6 color-secondary\">\n {{ $server_addr }}\n </span>\n </div>\n {{ end }}\n </div>\n\n <!-- Second row: MOTD & Stats if server is running, otherwise show status msg ... -->\n {{ if and ($is_running) (not $starting) }}\n {{ if and (not (eq $motd \"\")) ($displayMOTD) }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">\n {{ replaceMatches \"§.\" \"\" $motd }}\n </div>\n {{ end }}\n\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">\n {{ $version }} - {{ $online_players }}/{{ $max_players }} players - {{ $size }}\n </div>\n\n <!-- lots of assumptions about the boolean states meanings from crafty api.. -->\n {{ else if $starting }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is starting up..</div>\n {{ else if $importing }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is being imported..</div>\n {{ else if $updating }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is being updated..</div>\n {{ else if $crashed }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server has crashed!</div>\n {{ else }}\n <div style=\"font-size:0.9em; color:var(--color-secondary);\">Server is offline</div>\n {{ end }}\n </div>\n</div>";
}
]

View File

@@ -0,0 +1,97 @@
- type: custom-api
title: Crafty Controller — Minecraft Server
cache: 5s
allow-insecure: true
url: ${CRAFTY_URL}/api/v2/servers/${CRAFTY_SERVER_ID}/stats
headers:
Authorization: Bearer ${CRAFTY_API_TOKEN}
Accept: application/json
template: |
<!-- USER SETTINGS SECTION -->
<!-- Change true to false if you wish to not display the MOTD -->
{{ $displayMOTD := true }}
<!-- END OF USER SETTINGS SECTION -->
{{ $is_running := .JSON.Bool "data.running" }}
{{ $online_players := .JSON.Int "data.online" | formatNumber }}
{{ $max_players := .JSON.Int "data.max" | formatNumber }}
{{ $name := .JSON.String "data.world_name" }}
{{ $size := .JSON.String "data.world_size" }}
{{ $version := .JSON.String "data.version" }}
{{ $icon := .JSON.String "data.icon" }}
{{ $server_ip := .JSON.String "data.server_id.server_ip" }}
{{ $server_port := .JSON.String "data.server_id.server_port" }}
{{ $motd := .JSON.String "data.desc" }}
{{ $server_addr := "" }}
{{ if and ($is_running) (eq $server_ip "127.0.0.1") }}
{{ $server_addr = printf "%s:%s" (replaceMatches "https?://" "" "${CRAFTY_URL}") $server_port }}
{{ else if $is_running }}
{{ $server_addr = printf "%s:%s" $server_ip $server_port }}
{{ end }}
{{ $starting := false }}
{{ if and ($is_running) (eq $max_players "0") (eq $version "False") }}
{{ $starting = true }}
{{ end }}
<!-- I couldn't find documentation describing the "waiting_start" state or the other booleans below. Implementation might not be correct. -->
{{ $updating := .JSON.Bool "data.updating" }}
{{ $importing := .JSON.Bool "data.importing" }}
{{ $crashed := .JSON.Bool "data.crashed" }}
<div style="display:flex; align-items:center; gap:12px;">
<!-- Server Icon -->
<div style="width:40px; height:40px; flex-shrink:0; border-radius:4px; display:flex; justify-content:center; align-items:center; overflow:hidden;">
{{ if eq $icon "" }}
<img src="https://cdn.jsdelivr.net/gh/selfhst/icons/png/minecraft.png" style="width:100%; height:100%; object-fit:contain;" alt="Server icon">
{{ else }}
<img src="data:image/png;base64, {{ $icon }}" style="width:100%; height:100%; object-fit:contain;" alt="Server icon">
{{ end }}
</div>
<!-- Right side: Info -->
<div style="display:flex; flex-direction:column;">
<!-- First row: Server Name + IP -->
<div style="display:flex; align-items:center; gap:6px;">
<span class="size-h4 block text-truncate color-primary">
{{ $name }}
</span>
{{ if and ($is_running) (not $starting) (not (eq $server_addr "")) }}
<div style="font-size:0.9em; color:var(--color-secondary);">
<span class="size-h6 color-secondary">
{{ $server_addr }}
</span>
</div>
{{ end }}
</div>
<!-- Second row: MOTD & Stats if server is running, otherwise show status msg ... -->
{{ if and ($is_running) (not $starting) }}
{{ if and (not (eq $motd "")) ($displayMOTD) }}
<div style="font-size:0.9em; color:var(--color-secondary);">
{{ replaceMatches "§." "" $motd }}
</div>
{{ end }}
<div style="font-size:0.9em; color:var(--color-secondary);">
{{ $version }} - {{ $online_players }}/{{ $max_players }} players - {{ $size }}
</div>
<!-- lots of assumptions about the boolean states meanings from crafty api.. -->
{{ else if $starting }}
<div style="font-size:0.9em; color:var(--color-secondary);">Server is starting up..</div>
{{ else if $importing }}
<div style="font-size:0.9em; color:var(--color-secondary);">Server is being imported..</div>
{{ else if $updating }}
<div style="font-size:0.9em; color:var(--color-secondary);">Server is being updated..</div>
{{ else if $crashed }}
<div style="font-size:0.9em; color:var(--color-secondary);">Server has crashed!</div>
{{ else }}
<div style="font-size:0.9em; color:var(--color-secondary);">Server is offline</div>
{{ end }}
</div>
</div>

View File

@@ -0,0 +1,100 @@
{ pkgs, config, lib, ... }:
let
service = "yacreader";
cfg = config.modules.services.${service};
sec = config.sops.secrets;
homelab = config.modules.homelab;
in
{
options.modules.services.${service} = {
enable = lib.mkEnableOption "enables ${service}";
# set port options
port = lib.mkOption {
type = lib.types.int;
default = 7102;
description = "set port for ${service} (default: ${toString cfg.port}";
};
url = lib.mkOption {
type = lib.types.str;
default = "manga.${homelab.base_domain}";
description = "set domain for ${service}";
};
data_dir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/${service}";
description = "set data directory for ${service}";
};
ids = lib.mkOption {
type = lib.types.int;
default = cfg.port;
description = "set uid and pid of ${service} user (matches port by default)";
};
backup = lib.mkOption {
type = lib.types.bool;
default = true;
description = "enable backups for ${service}";
};
};
config = lib.mkIf cfg.enable {
# declare ${service} group
users.groups.${service} = { gid = lib.mkForce cfg.ids; };
# declare ${service} user
users.users.${service} = {
description = "${service} server user";
uid = lib.mkForce cfg.ids;
isSystemUser = true;
home = cfg.data_dir;
createHome = true;
group = "${service}";
extraGroups = [ "media" ];
};
# enable the ${service} service
services.${service} = {
enable = true;
openFirewall = true;
user = "${service}";
group = "${service}";
dataDir = cfg.data_dir;
settings = {
server.port = cfg.port;
};
};
# override umask to make permissions work out
systemd.services.${service}.serviceConfig = {
UMask = lib.mkForce "0007";
# User = "${service}";
# Group = "${service}";
};
# # open firewall
# networking.firewall.allowedTCPPorts = [ cfg.port ];
# add to glance local service
modules.services.glance.links.<category> = [{
title = service;
url = "https://${cfg.url}";
error-url = "http://${homelab.host_ip}:${toString cfg.port}";
check-url = "http://${homelab.host_ip}:${toString cfg.port}";
icon = "di:${service}"; }];
# sops.secrets = {
# "${service}_" = {
# owner = "${service}";
# group = "${service}";
# };
# };
# add to backups
modules.system.backups.baks = {
${service} = { paths = [ cfg.data_dir ]; };
};
};
}