@@ -46,7 +46,7 @@ let
4646 cmdlineArgs = cfg.extraFlags ++ [
4747 "--storage.tsdb.path=${workingDir}/data/"
4848 "--config.file=${prometheusYml}"
49− "--web.listen-address=${cfg.listenAddress}"
49+ "--web.listen-address=${cfg.listenAddress}:${builtins.toString cfg.port}"
5050 "--alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}"
5151 "--alertmanager.timeout=${toString cfg.alertmanagerTimeout}s"
5252 ] ++
@@ -489,9 +489,17 @@ in {
489489 '';
490490 };
491491
492+ port = mkOption {
493+ type = types.port;
494+ default = 9090;
495+ description = ''
496+ Port to listen on.
497+ '';
498+ };
499+
492500 listenAddress = mkOption {
493501 type = types.str;
494− default = "0.0.0.0:9090";
502+ default = "0.0.0.0";
495503 description = ''
496504 Address to listen on for the web interface, API, and telemetry.
497505 '';
@@ -619,6 +627,21 @@ in {
619627 };
620628
621629 config = mkIf cfg.enable {
630+ assertions = [
631+ ( let
632+ legacy = builtins.match "(.*):(.*)" cfg.listenAddress;
633+ in {
634+ assertion = legacy == null;
635+ message = ''
636+ Do not specify the port for Prometheus to listen on in the
637+ listenAddress option; use the port option instead:
638+ services.prometheus.listenAddress = ${builtins.elemAt legacy 0};
639+ services.prometheus.port = ${builtins.elemAt legacy 1};
640+ '';
641+ }
642+ )
643+ ];
644+
622645 users.groups.prometheus.gid = config.ids.gids.prometheus;
623646 users.users.prometheus = {
624647 description = "Prometheus daemon user";