1 { config, lib, pkgs, ... }: with lib;
3 cfg = config.services.iperf3;
6 enable = mkEnableOption "iperf3 network throughput testing server";
7 package = mkPackageOption pkgs "iperf3" { };
11 description = "Server port to listen on for iperf3 client requests.";
14 type = types.nullOr types.ints.unsigned;
16 description = "CPU affinity for the process.";
19 type = types.nullOr types.str;
21 description = "Bind to the specific interface associated with the given address.";
23 openFirewall = mkOption {
26 description = "Open ports in the firewall for iperf3.";
31 description = "Give more detailed output.";
33 forceFlush = mkOption {
36 description = "Force flushing output at every interval.";
41 description = "Emit debugging output.";
43 rsaPrivateKey = mkOption {
44 type = types.nullOr types.path;
46 description = "Path to the RSA private key (not password-protected) used to decrypt authentication credentials from the client.";
48 authorizedUsersFile = mkOption {
49 type = types.nullOr types.path;
51 description = "Path to the configuration file containing authorized users credentials to run iperf tests.";
53 extraFlags = mkOption {
54 type = types.listOf types.str;
56 description = "Extra flags to pass to iperf3(1).";
62 networking.firewall = mkIf cfg.openFirewall {
63 allowedTCPPorts = [ cfg.port ];
66 systemd.services.iperf3 = {
67 description = "iperf3 daemon";
68 unitConfig.Documentation = "man:iperf3(1) https://iperf.fr/iperf-doc.php";
69 wantedBy = [ "multi-user.target" ];
70 after = [ "network.target" ];
73 Restart = "on-failure";
76 PrivateDevices = true;
77 CapabilityBoundingSet = "";
78 NoNewPrivileges = true;
80 ${lib.getExe cfg.package} \
82 --port ${toString cfg.port} \
83 ${optionalString (cfg.affinity != null) "--affinity ${toString cfg.affinity}"} \
84 ${optionalString (cfg.bind != null) "--bind ${cfg.bind}"} \
85 ${optionalString (cfg.rsaPrivateKey != null) "--rsa-private-key-path ${cfg.rsaPrivateKey}"} \
86 ${optionalString (cfg.authorizedUsersFile != null) "--authorized-users-path ${cfg.authorizedUsersFile}"} \
87 ${optionalString cfg.verbose "--verbose"} \
88 ${optionalString cfg.debug "--debug"} \
89 ${optionalString cfg.forceFlush "--forceflush"} \
90 ${escapeShellArgs cfg.extraFlags}
96 options.services.iperf3 = api;
97 config = mkIf cfg.enable imp;