Refactor homelab modules

This commit is contained in:
Oliver Davies 2025-04-30 01:10:02 +01:00
parent e6f269b123
commit fe508bd127
9 changed files with 224 additions and 83 deletions

View file

@ -1,25 +1,51 @@
{ config, ... }:
{
services =
let
cfg = config.services.homepage-dashboard;
in
{
homepage-dashboard = {
config,
lib,
options,
...
}:
with lib;
let
cfg = homelab.services.${service};
homelab = config.homelab;
opts = options.services.${service};
service = "homepage-dashboard";
in
{
options.homelab.services.${service} = {
enable = mkEnableOption "Enable ${service}";
port = mkOption {
default = opts.listenPort.default;
type = types.port;
};
url = mkOption {
default = "${config.networking.hostName}.${homelab.baseDomain}";
type = types.str;
};
};
config = mkIf cfg.enable {
services = {
${service} = {
enable = true;
listenPort = 8097;
listenPort = cfg.port;
openFirewall = true;
services = (import ./services.nix { inherit config; });
widgets = import ./widgets.nix;
};
nginx.virtualHosts."nixedo.oliverdavies.uk" = {
nginx.virtualHosts.${cfg.url} = {
forceSSL = true;
useACMEHost = "oliverdavies.uk";
useACMEHost = homelab.baseDomain;
locations."/".proxyPass = "http://localhost:${toString cfg.listenPort}";
locations."/".proxyPass =
"http://localhost:${toString config.services.homepage-dashboard.listenPort}";
};
};
};
}

View file

@ -1,16 +1,34 @@
{ config, ... }:
{ config, lib, ... }:
with lib;
let
cfg = homelab.services.${service};
homelab = config.nixosModules.homelab;
service = "uptime-kuma";
in
{
services = {
uptime-kuma.enable = true;
options.nixosModules.homelab.services.${service} = {
enable = mkEnableOption "Enable ${service}";
nginx.virtualHosts."uptime.oliverdavies.uk" = {
forceSSL = true;
useACMEHost = "oliverdavies.uk";
url = mkOption {
default = "uptime.${homelab.baseDomain}";
type = types.str;
};
};
locations."/" = {
proxyPass = "http://localhost:${toString config.services.uptime-kuma.settings.PORT}";
recommendedProxySettings = true;
config = mkIf cfg.enable {
services = {
${service}.enable = true;
nginx.virtualHosts.${cfg.url} = {
forceSSL = true;
useACMEHost = homelab.baseDomain;
locations."/" = {
proxyPass = "http://localhost:${toString config.services.${service}.settings.PORT}";
recommendedProxySettings = true;
};
};
};
};