mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-19 16:40:32 +03:00

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
156 lines
4 KiB
Nix
156 lines
4 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
let
|
|
inherit (lib)
|
|
maintainers
|
|
types
|
|
literalExpression
|
|
escapeShellArg
|
|
escapeShellArgs
|
|
mkEnableOption
|
|
mkOption
|
|
mkRemovedOptionModule
|
|
mkIf
|
|
mkPackageOption
|
|
optionalString
|
|
concatMapStrings
|
|
concatStringsSep
|
|
;
|
|
|
|
cfg = config.services.mtr-exporter;
|
|
|
|
jobsConfig = pkgs.writeText "mtr-exporter.conf" (
|
|
concatMapStrings (job: ''
|
|
${job.name} -- ${job.schedule} -- ${concatStringsSep " " job.flags} ${job.address}
|
|
'') cfg.jobs
|
|
);
|
|
in
|
|
{
|
|
imports = [
|
|
(mkRemovedOptionModule [
|
|
"services"
|
|
"mtr-exporter"
|
|
"target"
|
|
] "Use services.mtr-exporter.jobs instead.")
|
|
(mkRemovedOptionModule [
|
|
"services"
|
|
"mtr-exporter"
|
|
"mtrFlags"
|
|
] "Use services.mtr-exporter.jobs.<job>.flags instead.")
|
|
];
|
|
|
|
options = {
|
|
services = {
|
|
mtr-exporter = {
|
|
enable = mkEnableOption "a Prometheus exporter for MTR";
|
|
|
|
address = mkOption {
|
|
type = types.str;
|
|
default = "127.0.0.1";
|
|
description = "Listen address for MTR exporter.";
|
|
};
|
|
|
|
port = mkOption {
|
|
type = types.port;
|
|
default = 8080;
|
|
description = "Listen port for MTR exporter.";
|
|
};
|
|
|
|
extraFlags = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [ ];
|
|
example = [ "-flag.deprecatedMetrics" ];
|
|
description = ''
|
|
Extra command line options to pass to MTR exporter.
|
|
'';
|
|
};
|
|
|
|
package = mkPackageOption pkgs "mtr-exporter" { };
|
|
|
|
mtrPackage = mkPackageOption pkgs "mtr" { };
|
|
|
|
jobs = mkOption {
|
|
description = "List of MTR jobs. Will be added to /etc/mtr-exporter.conf";
|
|
type = types.nonEmptyListOf (
|
|
types.submodule {
|
|
options = {
|
|
name = mkOption {
|
|
type = types.str;
|
|
description = "Name of ICMP pinging job.";
|
|
};
|
|
|
|
address = mkOption {
|
|
type = types.str;
|
|
example = "host.example.org:1234";
|
|
description = "Target address for MTR client.";
|
|
};
|
|
|
|
schedule = mkOption {
|
|
type = types.str;
|
|
default = "@every 60s";
|
|
example = "@hourly";
|
|
description = "Schedule of MTR checks. Also accepts Cron format.";
|
|
};
|
|
|
|
flags = mkOption {
|
|
type = with types; listOf str;
|
|
default = [ ];
|
|
example = [ "-G1" ];
|
|
description = "Additional flags to pass to MTR.";
|
|
};
|
|
};
|
|
}
|
|
);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
environment.etc."mtr-exporter.conf" = {
|
|
source = jobsConfig;
|
|
};
|
|
|
|
systemd.services.mtr-exporter = {
|
|
wantedBy = [ "multi-user.target" ];
|
|
requires = [ "network.target" ];
|
|
after = [ "network.target" ];
|
|
serviceConfig = {
|
|
ExecStart = ''
|
|
${cfg.package}/bin/mtr-exporter \
|
|
-mtr '${cfg.mtrPackage}/bin/mtr' \
|
|
-bind ${escapeShellArg "${cfg.address}:${toString cfg.port}"} \
|
|
-jobs '${jobsConfig}' \
|
|
${escapeShellArgs cfg.extraFlags}
|
|
'';
|
|
Restart = "on-failure";
|
|
# Hardening
|
|
CapabilityBoundingSet = [ "" ];
|
|
DynamicUser = true;
|
|
LockPersonality = true;
|
|
ProcSubset = "pid";
|
|
PrivateDevices = true;
|
|
PrivateUsers = true;
|
|
PrivateTmp = true;
|
|
ProtectClock = true;
|
|
ProtectControlGroups = true;
|
|
ProtectHome = true;
|
|
ProtectHostname = true;
|
|
ProtectKernelLogs = true;
|
|
ProtectKernelModules = true;
|
|
ProtectKernelTunables = true;
|
|
ProtectProc = "invisible";
|
|
ProtectSystem = "strict";
|
|
RestrictNamespaces = true;
|
|
RestrictRealtime = true;
|
|
};
|
|
};
|
|
};
|
|
|
|
meta.maintainers = with maintainers; [ jakubgs ];
|
|
}
|