From b6b9972d6008187a9f7e4a930abd1df2f0116831 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 25 Feb 2025 23:53:44 +0100 Subject: [PATCH] treewide: remove duplicate port settings --- modules/services/alertmanager/default.nix | 25 ++++++++++---------- modules/services/bazarr/default.nix | 2 +- modules/services/fritzbox/default.nix | 10 ++------ modules/services/gitea/default.nix | 12 +++------- modules/services/grafana/default.nix | 12 ++-------- modules/services/hedgedoc/default.nix | 13 +++------- modules/services/home-automation/default.nix | 15 +++--------- modules/services/jellyfin/default.nix | 4 ++-- modules/services/loki/default.nix | 17 +++++-------- modules/services/navidrome/default.nix | 12 ++-------- modules/services/nextcloud/default.nix | 9 +------ modules/services/node-exporter/default.nix | 1 - modules/services/paperless/default.nix | 13 +++------- modules/services/passworts/default.nix | 2 +- modules/services/photos/default.nix | 24 ++++++------------- modules/services/prometheus/default.nix | 12 ++-------- modules/services/prowlarr/default.nix | 1 + modules/services/radarr/default.nix | 1 + modules/services/sonarr/default.nix | 1 + modules/services/tandoor-recipes/default.nix | 9 +------ modules/services/vpn/default.nix | 6 ++--- 21 files changed, 58 insertions(+), 143 deletions(-) diff --git a/modules/services/alertmanager/default.nix b/modules/services/alertmanager/default.nix index aa6f70a..8139e41 100644 --- a/modules/services/alertmanager/default.nix +++ b/modules/services/alertmanager/default.nix @@ -12,12 +12,6 @@ in { options.my.services.alertmanager = with lib; { enable = mkEnableOption "Prometheus alertmanager for monitoring"; - port = mkOption { - type = types.port; - default = 9093; - example = 3002; - description = "Internal alertmanager port"; - }; }; config = lib.mkIf cfg.enable { @@ -34,20 +28,27 @@ in prometheus = { alertmanager = { enable = true; - inherit (cfg) port; configuration = import ./config.nix; webExternalUrl = "https://alerts.${domain}"; # fix issue: https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/4556 - extraFlags = [ "--cluster.advertise-address 127.0.0.1:${toString cfg.port}" ]; + extraFlags = [ + "--cluster.advertise-address 127.0.0.1:${toString config.services.prometheus.alertmanager.port}" + ]; }; - alertmanagers = [ { static_configs = [ { targets = [ "localhost:${toString cfg.port}" ]; } ]; } ]; + alertmanagers = [ + { + static_configs = [ + { targets = [ "localhost:${toString config.services.prometheus.alertmanager.port}" ]; } + ]; + } + ]; scrapeConfigs = [ { job_name = "alertmanager"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.prometheus.alertmanager.port}" ]; labels = { instance = config.networking.hostName; }; @@ -62,7 +63,7 @@ in { name = "Alertmanager"; type = "alertmanager"; - url = "http://localhost:${toString cfg.port}"; + url = "http://localhost:${toString config.services.prometheus.alertmanager.port}"; jsonData = { implementation = "prometheus"; handleGrafanaManagedAlerts = config.services.prometheus.enable; @@ -135,7 +136,7 @@ in my.services.webserver.virtualHosts = [ { subdomain = "alerts"; - inherit (cfg) port; + inherit (config.services.prometheus.alertmanager) port; } ]; diff --git a/modules/services/bazarr/default.nix b/modules/services/bazarr/default.nix index 90e2f0c..5b86235 100644 --- a/modules/services/bazarr/default.nix +++ b/modules/services/bazarr/default.nix @@ -3,7 +3,7 @@ let cfg = config.my.services.bazarr; inherit (config.networking) domain; - port = 6767; + port = config.services.bazarr.listenPort; in { options.my.services.bazarr = with lib; { diff --git a/modules/services/fritzbox/default.nix b/modules/services/fritzbox/default.nix index 2d0e948..0f38fd6 100644 --- a/modules/services/fritzbox/default.nix +++ b/modules/services/fritzbox/default.nix @@ -10,12 +10,6 @@ in { options.my.services.fritzbox = with lib; { enable = mkEnableOption "Fritzbox-Monitoring"; - port = mkOption { - type = types.port; - default = 9787; - example = 8080; - description = "Internal port"; - }; username = mkOption { type = types.str; @@ -34,7 +28,7 @@ in config = lib.mkIf cfg.enable { services = { prometheus.exporters.fritz = { - inherit (cfg) enable port; + inherit (cfg) enable; settings.devices = [ { inherit (cfg) username; @@ -48,7 +42,7 @@ in job_name = "fritzbox"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.prometheus.exporters.fritzbox.port}" ]; labels = { instance = config.networking.hostName; }; diff --git a/modules/services/gitea/default.nix b/modules/services/gitea/default.nix index 5638211..428e299 100644 --- a/modules/services/gitea/default.nix +++ b/modules/services/gitea/default.nix @@ -12,12 +12,6 @@ in { options.my.services.gitea = with lib; { enable = mkEnableOption "Gitea"; - port = mkOption { - type = types.port; - default = 3042; - example = 8080; - description = "Internal port"; - }; }; config = lib.mkIf cfg.enable { @@ -26,7 +20,7 @@ in enable = true; settings = { server = { - HTTP_PORT = cfg.port; + HTTP_PORT = 3042; ROOT_URL = "https://code.${domain}"; }; session.COOKIE_SECURE = true; @@ -44,7 +38,7 @@ in job_name = "gitea"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.gitea.settings.server.HTTP_PORT}" ]; labels = { instance = config.networking.hostName; }; @@ -69,7 +63,7 @@ in webserver.virtualHosts = [ { subdomain = "code"; - inherit (cfg) port; + port = config.services.gitea.settings.server.HTTP_PORT; } ]; diff --git a/modules/services/grafana/default.nix b/modules/services/grafana/default.nix index e9473bf..2e2829f 100644 --- a/modules/services/grafana/default.nix +++ b/modules/services/grafana/default.nix @@ -13,13 +13,6 @@ in options.my.services.grafana = with lib; { enable = mkEnableOption "Grafana for visualizing"; - port = mkOption { - type = types.port; - default = 9500; - example = 3001; - description = "Internal port"; - }; - username = mkOption { type = types.str; default = "felix"; @@ -42,7 +35,6 @@ in server = { domain = "visualization.${domain}"; root_url = "https://visualization.${domain}/"; - http_port = cfg.port; }; security = { @@ -69,7 +61,7 @@ in job_name = "grafana"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.grafana.settings.server.http_port}" ]; labels = { instance = config.networking.hostName; }; @@ -82,7 +74,7 @@ in my.services.webserver.virtualHosts = [ { subdomain = "visualization"; - inherit (cfg) port; + port = config.services.grafana.settings.server.http_port; } ]; diff --git a/modules/services/hedgedoc/default.nix b/modules/services/hedgedoc/default.nix index 2e47600..11ad8b6 100644 --- a/modules/services/hedgedoc/default.nix +++ b/modules/services/hedgedoc/default.nix @@ -26,13 +26,6 @@ in Additional settings. ''; }; - - port = mkOption { - type = types.port; - default = 3080; - example = 8080; - description = "Internal port for webui"; - }; }; config = lib.mkIf cfg.enable { @@ -42,7 +35,7 @@ in settings = { domain = "notes.${domain}"; - inherit (cfg) port; + port = 3080; protocolUseSSL = true; db = { dialect = "sqlite"; @@ -57,7 +50,7 @@ in job_name = "hedgedoc"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.hedgedoc.settings.port}" ]; labels = { instance = config.networking.hostName; }; @@ -79,7 +72,7 @@ in my.services.webserver.virtualHosts = [ { subdomain = "notes"; - inherit (cfg) port; + inherit (config.services.hedgedoc.settings) port; } ]; diff --git a/modules/services/home-automation/default.nix b/modules/services/home-automation/default.nix index dd7639d..e39ec2c 100644 --- a/modules/services/home-automation/default.nix +++ b/modules/services/home-automation/default.nix @@ -15,14 +15,6 @@ in package = lib.mkPackageOption pkgs "home-assistant" { }; - port = lib.mkOption { - type = lib.types.port; - default = 8123; - description = '' - Web interface port. - ''; - }; - extraComponents = mkOption { type = types.listOf (types.enum cfg.package.availableComponents); example = literalExpression '' @@ -99,10 +91,9 @@ in unit_system = "metric"; time_zone = cfg.timezone; external_url = "https://automation.${domain}"; - internal_url = "http://localhost:${toString cfg.port}"; + internal_url = "http://localhost:${toString config.services.home-assistant.config.http.server_port}"; }; http = { - server_port = cfg.port; use_x_forwarded_for = true; trusted_proxies = [ "127.0.0.1" @@ -126,7 +117,7 @@ in metrics_path = "/api/prometheus"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.home-assistant.config.http.server_port}" ]; labels = { instance = config.networking.hostName; }; @@ -148,7 +139,7 @@ in my.services.webserver.virtualHosts = [ { subdomain = "automation"; - inherit (cfg) port; + port = config.services.home-assistant.config.http.server_port; } { subdomain = "esphome"; diff --git a/modules/services/jellyfin/default.nix b/modules/services/jellyfin/default.nix index 601563c..819122d 100644 --- a/modules/services/jellyfin/default.nix +++ b/modules/services/jellyfin/default.nix @@ -8,7 +8,6 @@ let cfg = config.my.services.jellyfin; inherit (config.networking) domain; - port = 8096; # enable monitoring jellyfin-with-metrics = pkgs.jellyfin.overrideAttrs (attrs: { patches = @@ -50,7 +49,8 @@ in my.services.webserver.virtualHosts = [ { subdomain = "media"; - inherit port; + # jellyfin does not allow modification + port = 8096; } ]; diff --git a/modules/services/loki/default.nix b/modules/services/loki/default.nix index 2a1d474..ed605eb 100644 --- a/modules/services/loki/default.nix +++ b/modules/services/loki/default.nix @@ -7,18 +7,13 @@ }: let cfg = config.my.services.loki; + # no default port defined in nixpkgs + port = 3101; in { options.my.services.loki = with lib; { enable = mkEnableOption "loki log monitoring"; - port = mkOption { - type = types.port; - default = 3100; - example = 3002; - description = "Internal port"; - }; - rules = mkOption { type = types.attrsOf ( types.submodule { @@ -91,7 +86,7 @@ in configuration = { server = { http_listen_address = "localhost"; - http_listen_port = cfg.port; + http_listen_port = port; }; auth_enabled = false; @@ -113,7 +108,7 @@ in local.directory = "${config.services.loki.dataDir}/ruler"; }; rule_path = "${config.services.loki.dataDir}/rules"; - alertmanager_url = "http://localhost:${toString config.my.services.alertmanager.port}"; + alertmanager_url = "http://localhost:${toString config.services.prometheus.alertmanager.port}"; enable_alertmanager_v2 = true; }; @@ -151,7 +146,7 @@ in name = "Loki"; type = "loki"; access = "proxy"; - url = "http://localhost:${toString cfg.port}"; + url = "http://localhost:${toString port}"; } ]; dashboards.settings.providers = [ @@ -169,7 +164,7 @@ in job_name = "loki"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString port}" ]; labels = { instance = config.networking.hostName; }; diff --git a/modules/services/navidrome/default.nix b/modules/services/navidrome/default.nix index 5c341b3..94165f7 100644 --- a/modules/services/navidrome/default.nix +++ b/modules/services/navidrome/default.nix @@ -29,13 +29,6 @@ in ''; }; - port = mkOption { - type = types.port; - default = 4533; - example = 8080; - description = "Internal port for webui"; - }; - musicFolder = mkOption { type = types.str; example = "/mnt/music/"; @@ -49,7 +42,6 @@ in enable = true; settings = cfg.settings // { - Port = cfg.port; MusicFolder = cfg.musicFolder; LogLevel = "info"; Prometheus.Enabled = config.services.prometheus.enable; @@ -62,7 +54,7 @@ in job_name = "navidrome"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.navidrome.settings.Port}" ]; labels = { instance = config.networking.hostName; }; @@ -92,7 +84,7 @@ in my.services.webserver.virtualHosts = [ { subdomain = "music"; - inherit (cfg) port; + port = config.services.navidrome.settings.Port; } ]; diff --git a/modules/services/nextcloud/default.nix b/modules/services/nextcloud/default.nix index 501748f..8b50c82 100644 --- a/modules/services/nextcloud/default.nix +++ b/modules/services/nextcloud/default.nix @@ -47,12 +47,6 @@ in 'nextcloud' user. ''; }; - exporterPort = mkOption { - type = types.port; - default = 9205; - example = 8080; - description = "Internal port for the exporter"; - }; }; config = lib.mkIf cfg.enable { @@ -102,7 +96,6 @@ in url = "https://cloud.${domain}"; username = cfg.admin; passwordFile = cfg.exporterPasswordFile; - port = cfg.exporterPort; }; prometheus.scrapeConfigs = [ @@ -110,7 +103,7 @@ in job_name = "nextcloud"; static_configs = [ { - targets = [ "localhost:${toString cfg.exporterPort}" ]; + targets = [ "localhost:${toString config.services.prometheus.exporters.nextcloud.port}" ]; labels = { instance = config.networking.hostName; }; diff --git a/modules/services/node-exporter/default.nix b/modules/services/node-exporter/default.nix index 09b7d04..a131215 100644 --- a/modules/services/node-exporter/default.nix +++ b/modules/services/node-exporter/default.nix @@ -24,7 +24,6 @@ in "textfile" ]; extraFlags = [ "--collector.textfile.directory=/etc/prometheus-node-exporter-text-files" ]; - port = 9100; }; systemd = { enable = true; diff --git a/modules/services/paperless/default.nix b/modules/services/paperless/default.nix index f1ab611..208ad6b 100644 --- a/modules/services/paperless/default.nix +++ b/modules/services/paperless/default.nix @@ -14,17 +14,10 @@ in example = "/run/secrets/freshrss"; }; - port = mkOption { - type = types.port; - default = 28981; - example = 8080; - description = "Internal port for webui"; - }; - mediaDir = mkOption { type = types.path; description = "Location of the FreshRSS data."; - example = "/run/secrets/freshrss"; + example = "/data/docs"; }; settings = mkOption { @@ -37,7 +30,7 @@ in config = lib.mkIf cfg.enable { services.paperless = { enable = true; - inherit (cfg) port mediaDir passwordFile; + inherit (cfg) mediaDir passwordFile; settings = { PAPERLESS_OCR_LANGUAGE = "deu+eng"; } // cfg.settings; @@ -48,7 +41,7 @@ in my.services.webserver.virtualHosts = [ { subdomain = "docs"; - inherit (cfg) port; + inherit (config.services.paperless) port; } ]; diff --git a/modules/services/passworts/default.nix b/modules/services/passworts/default.nix index 31bbb60..e4d0598 100644 --- a/modules/services/passworts/default.nix +++ b/modules/services/passworts/default.nix @@ -6,7 +6,7 @@ let in { options.my.services.passworts = with lib; { - enable = mkEnableOption "Navidrome Music Server"; + enable = mkEnableOption "Passwords Server"; port = mkOption { type = types.port; default = 5010; diff --git a/modules/services/photos/default.nix b/modules/services/photos/default.nix index 102c296..0c31d53 100644 --- a/modules/services/photos/default.nix +++ b/modules/services/photos/default.nix @@ -3,6 +3,7 @@ let cfg = config.my.services.photos; inherit (config.networking) domain; + inherit (config.services.immich) port; in { options.my.services.photos = { @@ -16,14 +17,6 @@ in ''; }; - port = lib.mkOption { - type = lib.types.port; - default = 2283; - description = '' - Web interface port. - ''; - }; - settings = lib.mkOption { type = lib.types.anything; default = { }; @@ -46,18 +39,15 @@ in services.immich = { enable = true; # mediaLocation = path; - inherit (cfg) - secretsFile - port - ; + inherit (cfg) secretsFile; settings = { ffmpeg.transcode = "disabled"; server.externalDomain = "https://photos.${domain}"; } // cfg.settings; environment = { IMMICH_TELEMETRY_INCLUDE = "all"; - IMMICH_API_METRICS_PORT = toString (cfg.port + 1); - IMMICH_MICROSERVICES_METRICS_PORT = toString (cfg.port + 2); + IMMICH_API_METRICS_PORT = toString (port + 1); + IMMICH_MICROSERVICES_METRICS_PORT = toString (port + 2); }; }; @@ -67,14 +57,14 @@ in job_name = "immich"; static_configs = [ { - targets = [ "localhost:${toString (cfg.port + 1)}" ]; + targets = [ "localhost:${toString (port + 1)}" ]; labels = { instance = config.networking.hostName; service = "api"; }; } { - targets = [ "localhost:${toString (cfg.port + 2)}" ]; + targets = [ "localhost:${toString (port + 2)}" ]; labels = { instance = config.networking.hostName; service = "server"; @@ -88,7 +78,7 @@ in my.services.webserver.virtualHosts = [ { subdomain = "photos"; - inherit (cfg) port; + inherit port; } ]; diff --git a/modules/services/prometheus/default.nix b/modules/services/prometheus/default.nix index 1052120..e2b10c8 100644 --- a/modules/services/prometheus/default.nix +++ b/modules/services/prometheus/default.nix @@ -13,13 +13,6 @@ in options.my.services.prometheus = with lib; { enable = mkEnableOption "Prometheus for monitoring"; - port = mkOption { - type = types.port; - default = 9090; - example = 3002; - description = "Internal prometheus port"; - }; - scrapeInterval = mkOption { type = types.str; default = "15s"; @@ -88,7 +81,6 @@ in prometheus = { enable = true; webExternalUrl = "https://monitor.${domain}"; - inherit (cfg) port; inherit (cfg) retentionTime; @@ -123,7 +115,7 @@ in job_name = "prometheus"; static_configs = [ { - targets = [ "localhost:${toString cfg.port}" ]; + targets = [ "localhost:${toString config.services.prometheus.port}" ]; labels = { instance = config.networking.hostName; }; @@ -191,7 +183,7 @@ in webserver.virtualHosts = [ { subdomain = "monitor"; - inherit (cfg) port; + inherit (config.services.prometheus) port; } ]; diff --git a/modules/services/prowlarr/default.nix b/modules/services/prowlarr/default.nix index 8fd7921..bd971d7 100644 --- a/modules/services/prowlarr/default.nix +++ b/modules/services/prowlarr/default.nix @@ -3,6 +3,7 @@ let cfg = config.my.services.prowlarr; inherit (config.networking) domain; + # in 25.05 this might be configurable port = 9696; in { diff --git a/modules/services/radarr/default.nix b/modules/services/radarr/default.nix index 023378f..ae14872 100644 --- a/modules/services/radarr/default.nix +++ b/modules/services/radarr/default.nix @@ -3,6 +3,7 @@ let cfg = config.my.services.radarr; inherit (config.networking) domain; + # in 25.05 this might be configurable port = 7878; in { diff --git a/modules/services/sonarr/default.nix b/modules/services/sonarr/default.nix index 1a9f0be..f7b9150 100644 --- a/modules/services/sonarr/default.nix +++ b/modules/services/sonarr/default.nix @@ -3,6 +3,7 @@ let cfg = config.my.services.sonarr; inherit (config.networking) domain; + # in 25.05 this might be configurable port = 8989; in { diff --git a/modules/services/tandoor-recipes/default.nix b/modules/services/tandoor-recipes/default.nix index 9cd74d9..3d1b22b 100644 --- a/modules/services/tandoor-recipes/default.nix +++ b/modules/services/tandoor-recipes/default.nix @@ -7,25 +7,18 @@ in { options.my.services.tandoor-recipes = with lib; { enable = mkEnableOption "Tandoor Recipes"; - port = mkOption { - type = types.port; - default = 8089; - example = 8080; - description = "Internal port"; - }; }; config = lib.mkIf cfg.enable { services.tandoor-recipes = { enable = true; - inherit (cfg) port; }; # Proxy to Tandoor-Recipes my.services.webserver.virtualHosts = [ { subdomain = "recipes"; - inherit (cfg) port; + inherit (config.services.tandoor-recipes) port; } ]; diff --git a/modules/services/vpn/default.nix b/modules/services/vpn/default.nix index d92389e..0fc66ab 100644 --- a/modules/services/vpn/default.nix +++ b/modules/services/vpn/default.nix @@ -10,7 +10,7 @@ in isMaster = mkEnableOption "Headscale Master"; port = mkOption { type = types.port; - default = 8099; + default = 8090; example = 8080; description = "Internal port"; }; @@ -30,7 +30,7 @@ in settings = { dns.base_domain = "buehler.internal"; server_url = "https://vpn.${domain}"; - metrics_listen_addr = "127.0.0.1:8095"; + metrics_listen_addr = "127.0.0.1:8091"; log.level = "warn"; }; }; @@ -41,7 +41,7 @@ in job_name = "headscale"; static_configs = [ { - targets = [ "localhost:8095" ]; + targets = [ "localhost:8091" ]; labels = { instance = config.networking.hostName; };