{ 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 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}"; }; links = { services = lib.mkOption { type = lib.types.listOf lib.types.attrs; default = []; description = "list of links for ${service}"; }; mediastack = lib.mkOption { type = lib.types.listOf lib.types.attrs; 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 { # 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 = "snowbelle"; 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 = "services"; sites = cfg.links.services; } { type = "monitor"; cache = "1m"; title = "mediastack"; sites = cfg.links.mediastack; } { type = "monitor"; cache = "1m"; title = "system"; sites = cfg.links.system; } { type = "custom-api"; title = "minecraft recpro"; 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 = "\n\n\n{{ $displayMOTD := true }}\n\n\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\n{{ $updating := .JSON.Bool \"data.updating\" }}\n{{ $importing := .JSON.Bool \"data.importing\" }}\n{{ $crashed := .JSON.Bool \"data.crashed\" }}\n\n