2018-07-26 17:40:23 +00:00
|
|
|
{ config, lib, pkgs, ... }: with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.iperf3;
|
|
|
|
|
|
|
|
api = {
|
|
|
|
enable = mkEnableOption "iperf3 network throughput testing server";
|
|
|
|
port = mkOption {
|
|
|
|
type = types.ints.u16;
|
|
|
|
default = 5201;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Server port to listen on for iperf3 client requsts.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
affinity = mkOption {
|
|
|
|
type = types.nullOr types.ints.unsigned;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "CPU affinity for the process.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
bind = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Bind to the specific interface associated with the given address.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
2019-07-04 05:32:30 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Open ports in the firewall for iperf3.";
|
2019-07-04 05:32:30 +00:00
|
|
|
};
|
2018-07-26 17:40:23 +00:00
|
|
|
verbose = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Give more detailed output.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
forceFlush = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Force flushing output at every interval.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
debug = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Emit debugging output.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
rsaPrivateKey = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Path to the RSA private key (not password-protected) used to decrypt authentication credentials from the client.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
authorizedUsersFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Path to the configuration file containing authorized users credentials to run iperf tests.";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Extra flags to pass to iperf3(1).";
|
2018-07-26 17:40:23 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
imp = {
|
2019-07-04 05:32:30 +00:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.port ];
|
|
|
|
};
|
|
|
|
|
2018-07-26 17:40:23 +00:00
|
|
|
systemd.services.iperf3 = {
|
|
|
|
description = "iperf3 daemon";
|
|
|
|
unitConfig.Documentation = "man:iperf3(1) https://iperf.fr/iperf-doc.php";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 2;
|
|
|
|
DynamicUser = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.iperf3}/bin/iperf \
|
|
|
|
--server \
|
|
|
|
--port ${toString cfg.port} \
|
|
|
|
${optionalString (cfg.affinity != null) "--affinity ${toString cfg.affinity}"} \
|
|
|
|
${optionalString (cfg.bind != null) "--bind ${cfg.bind}"} \
|
|
|
|
${optionalString (cfg.rsaPrivateKey != null) "--rsa-private-key-path ${cfg.rsaPrivateKey}"} \
|
|
|
|
${optionalString (cfg.authorizedUsersFile != null) "--authorized-users-path ${cfg.authorizedUsersFile}"} \
|
|
|
|
${optionalString cfg.verbose "--verbose"} \
|
|
|
|
${optionalString cfg.debug "--debug"} \
|
|
|
|
${optionalString cfg.forceFlush "--forceflush"} \
|
|
|
|
${escapeShellArgs cfg.extraFlags}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.services.iperf3 = api;
|
|
|
|
config = mkIf cfg.enable imp;
|
|
|
|
}
|