Refactor homelab ports

This commit is contained in:
Oliver Davies 2025-05-03 22:30:39 +01:00
parent 518bfe9cd4
commit f42833545b
10 changed files with 61 additions and 61 deletions

View file

@ -1,4 +1,6 @@
{ {
imports = [ ./ports.nix ];
services = { services = {
postgresqlBackup.enable = true; postgresqlBackup.enable = true;
}; };
@ -19,13 +21,7 @@
gitea-actions-runner.enable = true; gitea-actions-runner.enable = true;
home-assistant.enable = true; home-assistant.enable = true;
homepage-dashboard.enable = true;
homepage-dashboard = {
enable = true;
port = 8097;
};
immich.enable = true; immich.enable = true;
jellyfin.enable = true; jellyfin.enable = true;
paperless.enable = true; paperless.enable = true;

View file

@ -1,10 +1,11 @@
{ lib, ... }: { config, lib, ... }:
let let
port = 8082; service = "pihole";
port = config.homelab.ports.${service};
in in
{ {
virtualisation.oci-containers.containers."pihole" = { virtualisation.oci-containers.containers.${service} = {
image = "pihole/pihole:latest"; image = "pihole/pihole:latest";
environment = { environment = {
@ -22,7 +23,7 @@ in
"53:53/tcp" "53:53/tcp"
"53:53/udp" "53:53/udp"
"67:67/udp" "67:67/udp"
"${toString port}:80/tcp" "${port}:80/tcp"
]; ];
log-driver = "journald"; log-driver = "journald";

View file

@ -11,16 +11,13 @@ let
cfg = homelab.services.${service}; cfg = homelab.services.${service};
service = "tubearchivist"; service = "tubearchivist";
homelab = config.homelab; homelab = config.homelab;
port = homelab.ports.${service};
in in
{ {
options.homelab.services.${service} = { options.homelab.services.${service} = {
enable = mkEnableOption "Enable ${service}"; enable = mkEnableOption "Enable ${service}";
port = mkOption {
default = 8099;
type = types.port;
};
url = mkOption { url = mkOption {
default = "${service}.${homelab.domain}"; default = "${service}.${homelab.domain}";
type = types.str; type = types.str;
@ -177,7 +174,7 @@ in
]; ];
ports = [ ports = [
"${toString cfg.port}:8000/tcp" "${toString port}:8000/tcp"
]; ];
dependsOn = [ dependsOn = [
@ -321,7 +318,7 @@ in
useACMEHost = homelab.domain; useACMEHost = homelab.domain;
locations."/" = { locations."/" = {
proxyPass = "http://localhost:${toString cfg.port}"; proxyPass = "http://localhost:${toString port}";
recommendedProxySettings = true; recommendedProxySettings = true;
proxyWebsockets = true; proxyWebsockets = true;

View file

@ -1,7 +1,7 @@
{ config, ... }: { config, ... }:
let let
sites = import ./sites.nix; sites = import ./sites.nix { ports = config.homelab.ports; };
in in
{ {
services = { services = {

View file

@ -1,15 +0,0 @@
{
bootstrap-with-tailwind = 8081;
eric = 8084;
florida-drupalcamp-tailwind-css = 8083;
luke = 8094;
phpsw-sculpin-demo = 8085;
rebuilding-acquia = 8086;
rebuilding-bartik = 8087;
rebuilding-bristol-js = 8088;
rebuilding-symfony = 8089;
tailwindcss-demo = 8090;
talking-drupal-tailwindcss = 8093;
wp-tailwind = 8091;
zet = 8092;
}

View file

@ -1,20 +1,14 @@
{ ports }:
let let
domain = "oliverdavies.uk";
ports = import ./ports.nix;
mkSite = mkSite =
name: overrides: name: overrides:
let let
root = "/var/www/vhosts/${name}" + (overrides.rootSuffix or ""); root = "/var/www/vhosts/${name}" + (overrides.rootSuffix or "");
port = ports."nginx-${name}";
url = "${name}.oliverdavies.uk";
in in
{ { inherit port root url; } // overrides;
inherit root;
port = ports.${name};
url = "${name}.${domain}";
}
// overrides;
sites = [ sites = [
(mkSite "eric" { (mkSite "eric" {

View file

@ -1,5 +1,8 @@
{ config, ... }:
let let
port = 8095; ports = config.homelab.ports;
port = ports.nginx-website-sculpin;
redirects = import ./www.oliverdavies.uk-redirects.nix; redirects = import ./www.oliverdavies.uk-redirects.nix;
@ -18,7 +21,7 @@ let
"tome-test" "tome-test"
]; ];
port = 8098; port = ports.nginx-website-tome;
}; };
tomeLocations = builtins.listToAttrs ( tomeLocations = builtins.listToAttrs (

35
hosts/nixedo/ports.nix Normal file
View file

@ -0,0 +1,35 @@
{ lib, ... }:
let
inherit (lib) mkOption types;
in
{
options.homelab.ports = mkOption {
internal = true;
type = types.attrsOf types.port;
};
config.homelab.ports = {
homepage-dashboard = 8097;
pihole = 8082;
tubearchivist = 8099;
vaultwarden = 8022;
nginx-website-sculpin = 8095;
nginx-website-tome = 8098;
nginx-bootstrap-with-tailwind = 8081;
nginx-eric = 8084;
nginx-florida-drupalcamp-tailwind-css = 8083;
nginx-luke = 8094;
nginx-phpsw-sculpin-demo = 8085;
nginx-rebuilding-acquia = 8086;
nginx-rebuilding-bartik = 8087;
nginx-rebuilding-bristol-js = 8088;
nginx-rebuilding-symfony = 8089;
nginx-tailwindcss-demo = 8090;
nginx-talking-drupal-tailwindcss = 8093;
nginx-wp-tailwind = 8091;
nginx-zet = 8092;
};
}

View file

@ -1,27 +1,16 @@
{ { config, lib, ... }:
config,
lib,
options,
...
}:
with lib; with lib;
let let
cfg = homelab.services.${service}; cfg = homelab.services.${service};
homelab = config.homelab; homelab = config.homelab;
opts = options.services.${service};
service = "homepage-dashboard"; service = "homepage-dashboard";
in in
{ {
options.homelab.services.${service} = { options.homelab.services.${service} = {
enable = mkEnableOption "Enable ${service}"; enable = mkEnableOption "Enable ${service}";
port = mkOption {
default = opts.listenPort.default;
type = types.port;
};
url = mkOption { url = mkOption {
default = "${config.networking.hostName}.${homelab.domain}"; default = "${config.networking.hostName}.${homelab.domain}";
type = types.str; type = types.str;
@ -32,7 +21,7 @@ in
services = { services = {
${service} = { ${service} = {
enable = true; enable = true;
listenPort = cfg.port; listenPort = homelab.ports.${service};
openFirewall = true; openFirewall = true;
customCSS = '' customCSS = ''

View file

@ -55,7 +55,7 @@ in
config = { config = {
DOMAIN = "https://${cfg.url}"; DOMAIN = "https://${cfg.url}";
ROCKET_ADDRESS = "127.0.0.1"; ROCKET_ADDRESS = "127.0.0.1";
ROCKET_PORT = 8222; ROCKET_PORT = homelab.ports.${service};
SIGNUPS_ALLOWED = false; SIGNUPS_ALLOWED = false;
}; };
}; };