74 lines
1.9 KiB
Nix

{
inputs,
lib,
config,
...
}:
with lib; let
cfg = config.my.services.homepage-dashboard;
inherit (config.my.server) domain proxyIP firewallInterface;
in {
disabledModules = ["services/misc/homepage-dashboard.nix"];
imports = [
# Use homepage-dashboard service from nixos-unstable channel.
"${inputs.unstable}/nixos/modules/services/misc/homepage-dashboard.nix"
];
options.my.services.homepage-dashboard = {
enable = mkEnableOption "Homepage Dashboard";
proxy = mkEnableOption "Homepage Dashboard reverse proxy entry";
port = mkOption {
type = types.port;
default = 8082;
description = "HTTP port for the homepage-dashboard service.";
};
services = mkOption {
type = types.attrs;
default = {};
description = "Attrset of services by group.";
example = ''
{
Group = {
App = {
href = "https://example.com";
description = "An amazing app!";
};
};
}
'';
};
};
config = mkMerge [
(mkIf cfg.enable {
services.homepage-dashboard = {
enable = true;
listenPort = cfg.port;
settings.logpath = "/var/log/homepage-dashboard";
# Convert services to YAML format
services =
lib.mapAttrsToList (
groupName: groupAttrs: {
${groupName} = (
lib.mapAttrsToList (
serviceName: serviceAttrs: {${serviceName} = serviceAttrs;}
)
groupAttrs
);
}
)
cfg.services;
};
systemd.services.homepage-dashboard.environment.LOG_TARGETS = "stdout";
networking.firewall.interfaces."${firewallInterface}".allowedTCPPorts = [cfg.port];
})
(mkIf cfg.proxy {
services.caddy.virtualHosts."${domain}".extraConfig = ''
reverse_proxy http://${proxyIP}:${toString cfg.port}
'';
})
];
}