0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-19 08:31:01 +03:00
nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/mysqld.nix
Silvan Mosberger d9d87c5196 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev 0128fbb0a5
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:29:24 +01:00

75 lines
1.9 KiB
Nix

{
config,
lib,
pkgs,
options,
...
}:
let
cfg = config.services.prometheus.exporters.mysqld;
inherit (lib)
types
mkOption
mkIf
mkForce
cli
concatStringsSep
optionalString
escapeShellArgs
;
in
{
port = 9104;
extraOpts = {
telemetryPath = mkOption {
type = types.str;
default = "/metrics";
description = ''
Path under which to expose metrics.
'';
};
runAsLocalSuperUser = mkOption {
type = types.bool;
default = false;
description = ''
Whether to run the exporter as {option}`services.mysql.user`.
'';
};
configFile = mkOption {
type = types.path;
example = "/var/lib/prometheus-mysqld-exporter.cnf";
description = ''
Path to the services config file.
See <https://github.com/prometheus/mysqld_exporter#running> for more information about
the available options.
::: {.warn}
Please do not store this file in the nix store if you choose to include any credentials here,
as it would be world-readable.
:::
'';
};
};
serviceOpts = {
serviceConfig = {
DynamicUser = !cfg.runAsLocalSuperUser;
User = mkIf cfg.runAsLocalSuperUser (mkForce config.services.mysql.user);
LoadCredential = mkIf (cfg.configFile != null) (mkForce ("config:" + cfg.configFile));
ExecStart = concatStringsSep " " [
"${pkgs.prometheus-mysqld-exporter}/bin/mysqld_exporter"
"--web.listen-address=${cfg.listenAddress}:${toString cfg.port}"
"--web.telemetry-path=${cfg.telemetryPath}"
(optionalString (cfg.configFile != null) ''--config.my-cnf=''${CREDENTIALS_DIRECTORY}/config'')
(escapeShellArgs cfg.extraFlags)
];
RestrictAddressFamilies = [
# The exporter can be configured to talk to a local mysql server via a unix socket.
"AF_UNIX"
];
};
};
}