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

@ -19,7 +19,27 @@
core.openssh.enable = true; core.openssh.enable = true;
cli.podman.enable = true; cli.podman.enable = true;
desktop.dconf.enable = true; desktop.dconf.enable = true;
homelab.immich.enable = true;
homelab = {
enable = true;
baseDomain = "oliverdavies.uk";
services = {
audiobookshelf.enable = true;
forgejo = {
enable = true;
cloudflared.tunnelId = "e1514105-327f-4984-974e-e2fbaca76466";
};
immich.enable = true;
jellyfin.enable = true;
paperless.enable = true;
uptime-kuma.enable = true;
};
};
}; };
services.logind.lidSwitchExternalPower = "ignore"; services.logind.lidSwitchExternalPower = "ignore";

View file

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

View file

@ -1,4 +1,17 @@
{ lib, ... }:
with lib;
{ {
options.nixosModules.homelab = {
enable = mkEnableOption "Enable homelab services and configuration";
baseDomain = mkOption {
description = "The base domain to use for this homelab.";
type = types.str;
};
};
imports = [ imports = [
./acme.nix ./acme.nix
./audiobookshelf.nix ./audiobookshelf.nix

View file

@ -1,26 +1,42 @@
{ config, ... }: { config, lib, ... }:
with lib;
let
cfg = homelab.services.${service};
homelab = config.nixosModules.homelab;
service = "forgejo";
in
{ {
services = { options.nixosModules.homelab.services.${service} = {
forgejo = { enable = mkEnableOption "Enable ${service}";
enable = true;
stateDir = "/var/www/forgejo";
settings = { cloudflared.tunnelId = mkOption {
server = { example = "00000000-0000-0000-0000-000000000000";
DOMAIN = "code.oliverdavies.uk"; type = types.str;
HTTP_PORT = 2223;
};
service = {
DISABLE_REGISTRATION = true;
};
};
}; };
cloudflared.tunnels."e1514105-327f-4984-974e-e2fbaca76466".ingress = { url = mkOption {
"code.oliverdavies.uk" = default = "code.${homelab.baseDomain}";
"http://localhost:${toString config.services.forgejo.settings.server.HTTP_PORT}"; type = types.str;
};
};
config = mkIf cfg.enable {
services = {
${service} = {
enable = true;
stateDir = "/var/www/${service}";
settings = {
server.DOMAIN = cfg.url;
service.DISABLE_REGISTRATION = true;
};
};
cloudflared.tunnels.${cfg.cloudflared.tunnelId}.ingress = {
${cfg.url} = "http://localhost:${toString config.services.${service}.settings.server.HTTP_PORT}";
};
}; };
}; };
} }

View file

@ -8,24 +8,31 @@
with lib; with lib;
let let
cfg = config.nixosModules.homelab.immich; cfg = homelab.services.${service};
homelab = config.nixosModules.homelab;
service = "immich";
in in
{ {
options.nixosModules.homelab.immich = { options.nixosModules.homelab.services.${service} = {
enable = mkEnableOption "Enable immich"; enable = mkEnableOption "Enable ${service}";
url = mkOption {
default = "photos.${homelab.baseDomain}";
type = types.str;
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
services = { services = {
immich = { ${service} = {
enable = true; enable = true;
group = "media"; group = "media";
mediaLocation = "/mnt/media/immich"; mediaLocation = "/mnt/media/${service}";
}; };
nginx.virtualHosts."photos.oliverdavies.uk" = { nginx.virtualHosts."${cfg.url}" = {
forceSSL = true; forceSSL = true;
useACMEHost = "oliverdavies.uk"; useACMEHost = homelab.baseDomain;
locations."/" = { locations."/" = {
proxyPass = "http://localhost:${toString config.services.immich.port}"; proxyPass = "http://localhost:${toString config.services.immich.port}";

View file

@ -1,22 +1,38 @@
{ config, lib, ... }:
with lib;
let
cfg = homelab.services.${service};
homelab = config.nixosModules.homelab;
service = "jellyfin";
in
{ {
services = options.nixosModules.homelab.services.${service} = {
let enable = mkEnableOption "Enable ${service}";
port = 8096;
in url = mkOption {
{ default = "${service}.${homelab.baseDomain}";
jellyfin = { type = types.str;
};
};
config = mkIf cfg.enable {
services = {
${service} = {
enable = true; enable = true;
openFirewall = true;
configDir = "/mnt/media/${service}";
group = "media"; group = "media";
configDir = "/mnt/media/jellyfin"; openFirewall = true;
}; };
nginx.virtualHosts."jellyfin.oliverdavies.uk" = { nginx.virtualHosts."${cfg.url}" = {
forceSSL = true; forceSSL = true;
useACMEHost = "oliverdavies.uk"; useACMEHost = homelab.baseDomain;
locations."/" = { locations."/" = {
proxyPass = "http://localhost:${toString port}"; proxyPass = "http://localhost:8096";
recommendedProxySettings = true; recommendedProxySettings = true;
extraConfig = '' extraConfig = ''
@ -25,4 +41,5 @@
}; };
}; };
}; };
};
} }

View file

@ -1,30 +1,43 @@
{ config, ... }: { config, lib, ... }:
with lib;
let
cfg = homelab.services.paperless;
homelab = config.nixosModules.homelab;
service = "paperless";
in
{ {
services = options.nixosModules.homelab.services.${service} = {
let enable = mkEnableOption "Enable ${service}";
cfg = config.services.paperless;
hostname = "paperless.oliverdavies.uk"; url = mkOption {
in default = "${service}.${homelab.baseDomain}";
{ type = types.str;
paperless = { };
};
config = mkIf cfg.enable {
services = {
${service} = {
enable = true; enable = true;
dataDir = "/mnt/media/paperless"; dataDir = "/mnt/media/${service}";
settings = { settings = {
PAPERLESS_URL = "https://${hostname}"; PAPERLESS_URL = "https://${cfg.url}";
}; };
}; };
nginx.virtualHosts."${hostname}" = { nginx.virtualHosts."${cfg.url}" = {
forceSSL = true; forceSSL = true;
useACMEHost = "oliverdavies.uk"; useACMEHost = homelab.baseDomain;
locations."/" = { locations."/" = {
proxyPass = "http://localhost:${toString cfg.port}"; proxyPass = "http://localhost:${toString config.services.${service}.port}";
recommendedProxySettings = true; recommendedProxySettings = true;
}; };
}; };
}; };
};
} }

View file

@ -1,25 +1,51 @@
{ config, ... }:
{ {
services = config,
let lib,
cfg = config.services.homepage-dashboard; options,
in ...
{ }:
homepage-dashboard = {
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; enable = true;
listenPort = 8097; listenPort = cfg.port;
openFirewall = true; openFirewall = true;
services = (import ./services.nix { inherit config; }); services = (import ./services.nix { inherit config; });
widgets = import ./widgets.nix; widgets = import ./widgets.nix;
}; };
nginx.virtualHosts."nixedo.oliverdavies.uk" = { nginx.virtualHosts.${cfg.url} = {
forceSSL = true; 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 = { options.nixosModules.homelab.services.${service} = {
uptime-kuma.enable = true; enable = mkEnableOption "Enable ${service}";
nginx.virtualHosts."uptime.oliverdavies.uk" = { url = mkOption {
forceSSL = true; default = "uptime.${homelab.baseDomain}";
useACMEHost = "oliverdavies.uk"; type = types.str;
};
};
locations."/" = { config = mkIf cfg.enable {
proxyPass = "http://localhost:${toString config.services.uptime-kuma.settings.PORT}"; services = {
recommendedProxySettings = true; ${service}.enable = true;
nginx.virtualHosts.${cfg.url} = {
forceSSL = true;
useACMEHost = homelab.baseDomain;
locations."/" = {
proxyPass = "http://localhost:${toString config.services.${service}.settings.PORT}";
recommendedProxySettings = true;
};
}; };
}; };
}; };