{ pkgs, lib, config, ... }: let enabled = config.mod.homepage.enable; nginxEnabled = config.mod.nginx.enable; services = config.mod.homepage.services; serviceToCard = svc: ''
${svc.name}
${svc.description}
:${toString svc.port}
''; page = pkgs.writeTextDir "index.html" '' manatee

manatee

${lib.concatMapStrings serviceToCard services}
''; in { options = { mod.homepage = { enable = lib.mkEnableOption "Enable homepage module"; services = lib.mkOption { type = lib.types.listOf (lib.types.submodule { options = { name = lib.mkOption { type = lib.types.str; }; port = lib.mkOption { type = lib.types.port; }; description = lib.mkOption { type = lib.types.str; }; }; }); default = [ ]; description = "Services to display on the homepage"; }; }; }; config = lib.mkIf (enabled && nginxEnabled) { services.nginx.virtualHosts."homepage" = { listen = [ { addr = "0.0.0.0"; port = 9999; } ]; root = page; locations."/" = { index = "index.html"; }; }; networking.firewall.allowedTCPPorts = [ 9999 ]; }; }