nixos/prometheus-node-exporter: use socket activation

Run node_exporter with `--web.systemd-socket` and move the
listen-address/port configuration into a companion `.socket` unit.

Closes https://github.com/NixOS/nixpkgs/issues/510379
This commit is contained in:
Ilan Joselevich
2026-04-16 20:50:20 +01:00
parent 2737d78336
commit 6a7bcd4fbb
@@ -39,6 +39,7 @@ in
'';
};
};
serviceOpts = {
serviceConfig = {
DynamicUser = false;
@@ -47,7 +48,7 @@ in
${pkgs.prometheus-node-exporter}/bin/node_exporter \
${concatMapStringsSep " " (x: "--collector." + x) cfg.enabledCollectors} \
${concatMapStringsSep " " (x: "--no-collector." + x) cfg.disabledCollectors} \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} ${concatStringsSep " " cfg.extraFlags}
--web.systemd-socket ${concatStringsSep " " cfg.extraFlags}
'';
RestrictAddressFamilies =
optionals (collectorIsEnabled "logind" || collectorIsEnabled "systemd") [
@@ -67,4 +68,8 @@ in
ProtectHome = true;
};
};
socketOpts = {
socketConfig.ListenStream = "${cfg.listenAddress}:${toString cfg.port}";
};
}