diff --git a/hosts/nixedo/homelab.nix b/hosts/nixedo/homelab.nix index 5ddb8541..837e968a 100644 --- a/hosts/nixedo/homelab.nix +++ b/hosts/nixedo/homelab.nix @@ -1,4 +1,6 @@ { + imports = [ ./ports.nix ]; + services = { postgresqlBackup.enable = true; }; @@ -19,13 +21,7 @@ gitea-actions-runner.enable = true; home-assistant.enable = true; - - homepage-dashboard = { - enable = true; - - port = 8097; - }; - + homepage-dashboard.enable = true; immich.enable = true; jellyfin.enable = true; paperless.enable = true; diff --git a/hosts/nixedo/modules/containers/pi-hole.nix b/hosts/nixedo/modules/containers/pi-hole.nix index 9923d87d..7d523e89 100644 --- a/hosts/nixedo/modules/containers/pi-hole.nix +++ b/hosts/nixedo/modules/containers/pi-hole.nix @@ -1,10 +1,11 @@ -{ lib, ... }: +{ config, lib, ... }: let - port = 8082; + service = "pihole"; + port = config.homelab.ports.${service}; in { - virtualisation.oci-containers.containers."pihole" = { + virtualisation.oci-containers.containers.${service} = { image = "pihole/pihole:latest"; environment = { @@ -22,7 +23,7 @@ in "53:53/tcp" "53:53/udp" "67:67/udp" - "${toString port}:80/tcp" + "${port}:80/tcp" ]; log-driver = "journald"; diff --git a/hosts/nixedo/modules/containers/tubearchivist.nix b/hosts/nixedo/modules/containers/tubearchivist.nix index 8dfa947e..12f57dd8 100644 --- a/hosts/nixedo/modules/containers/tubearchivist.nix +++ b/hosts/nixedo/modules/containers/tubearchivist.nix @@ -11,16 +11,13 @@ let cfg = homelab.services.${service}; service = "tubearchivist"; homelab = config.homelab; + + port = homelab.ports.${service}; in { options.homelab.services.${service} = { enable = mkEnableOption "Enable ${service}"; - port = mkOption { - default = 8099; - type = types.port; - }; - url = mkOption { default = "${service}.${homelab.domain}"; type = types.str; @@ -177,7 +174,7 @@ in ]; ports = [ - "${toString cfg.port}:8000/tcp" + "${toString port}:8000/tcp" ]; dependsOn = [ @@ -321,7 +318,7 @@ in useACMEHost = homelab.domain; locations."/" = { - proxyPass = "http://localhost:${toString cfg.port}"; + proxyPass = "http://localhost:${toString port}"; recommendedProxySettings = true; proxyWebsockets = true; diff --git a/hosts/nixedo/modules/nginx/default.nix b/hosts/nixedo/modules/nginx/default.nix index be60c28a..6d397a25 100644 --- a/hosts/nixedo/modules/nginx/default.nix +++ b/hosts/nixedo/modules/nginx/default.nix @@ -1,7 +1,7 @@ { config, ... }: let - sites = import ./sites.nix; + sites = import ./sites.nix { ports = config.homelab.ports; }; in { services = { diff --git a/hosts/nixedo/modules/nginx/ports.nix b/hosts/nixedo/modules/nginx/ports.nix index fb75d455..e69de29b 100644 --- a/hosts/nixedo/modules/nginx/ports.nix +++ b/hosts/nixedo/modules/nginx/ports.nix @@ -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; -} diff --git a/hosts/nixedo/modules/nginx/sites.nix b/hosts/nixedo/modules/nginx/sites.nix index 4a982436..b5841173 100644 --- a/hosts/nixedo/modules/nginx/sites.nix +++ b/hosts/nixedo/modules/nginx/sites.nix @@ -1,20 +1,14 @@ +{ ports }: + let - domain = "oliverdavies.uk"; - - ports = import ./ports.nix; - mkSite = name: overrides: let root = "/var/www/vhosts/${name}" + (overrides.rootSuffix or ""); + port = ports."nginx-${name}"; + url = "${name}.oliverdavies.uk"; in - { - inherit root; - - port = ports.${name}; - url = "${name}.${domain}"; - } - // overrides; + { inherit port root url; } // overrides; sites = [ (mkSite "eric" { diff --git a/hosts/nixedo/modules/nginx/www.oliverdavies.uk.nix b/hosts/nixedo/modules/nginx/www.oliverdavies.uk.nix index 600b4ed1..ce3178bf 100644 --- a/hosts/nixedo/modules/nginx/www.oliverdavies.uk.nix +++ b/hosts/nixedo/modules/nginx/www.oliverdavies.uk.nix @@ -1,5 +1,8 @@ +{ config, ... }: + let - port = 8095; + ports = config.homelab.ports; + port = ports.nginx-website-sculpin; redirects = import ./www.oliverdavies.uk-redirects.nix; @@ -18,7 +21,7 @@ let "tome-test" ]; - port = 8098; + port = ports.nginx-website-tome; }; tomeLocations = builtins.listToAttrs ( diff --git a/hosts/nixedo/ports.nix b/hosts/nixedo/ports.nix new file mode 100644 index 00000000..26811b8f --- /dev/null +++ b/hosts/nixedo/ports.nix @@ -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; + }; +} diff --git a/hosts/nixedo/services/homepage/default.nix b/hosts/nixedo/services/homepage/default.nix index 18d20af2..df0b543b 100644 --- a/hosts/nixedo/services/homepage/default.nix +++ b/hosts/nixedo/services/homepage/default.nix @@ -1,27 +1,16 @@ -{ - config, - lib, - options, - ... -}: +{ config, lib, ... }: 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.domain}"; type = types.str; @@ -32,7 +21,7 @@ in services = { ${service} = { enable = true; - listenPort = cfg.port; + listenPort = homelab.ports.${service}; openFirewall = true; customCSS = '' diff --git a/hosts/nixedo/services/vaultwarden.nix b/hosts/nixedo/services/vaultwarden.nix index 8c00fc13..7c97cc82 100644 --- a/hosts/nixedo/services/vaultwarden.nix +++ b/hosts/nixedo/services/vaultwarden.nix @@ -55,7 +55,7 @@ in config = { DOMAIN = "https://${cfg.url}"; ROCKET_ADDRESS = "127.0.0.1"; - ROCKET_PORT = 8222; + ROCKET_PORT = homelab.ports.${service}; SIGNUPS_ALLOWED = false; }; };