1 { config, lib, pkgs, ... }: with lib;
3 cfg = config.services.iperf3;
6 enable = mkEnableOption (lib.mdDoc "iperf3 network throughput testing server");
10 description = lib.mdDoc "Server port to listen on for iperf3 client requsts.";
13 type = types.nullOr types.ints.unsigned;
15 description = lib.mdDoc "CPU affinity for the process.";
18 type = types.nullOr types.str;
20 description = lib.mdDoc "Bind to the specific interface associated with the given address.";
22 openFirewall = mkOption {
25 description = lib.mdDoc "Open ports in the firewall for iperf3.";
30 description = lib.mdDoc "Give more detailed output.";
32 forceFlush = mkOption {
35 description = lib.mdDoc "Force flushing output at every interval.";
40 description = lib.mdDoc "Emit debugging output.";
42 rsaPrivateKey = mkOption {
43 type = types.nullOr types.path;
45 description = lib.mdDoc "Path to the RSA private key (not password-protected) used to decrypt authentication credentials from the client.";
47 authorizedUsersFile = mkOption {
48 type = types.nullOr types.path;
50 description = lib.mdDoc "Path to the configuration file containing authorized users credentials to run iperf tests.";
52 extraFlags = mkOption {
53 type = types.listOf types.str;
55 description = lib.mdDoc "Extra flags to pass to iperf3(1).";
61 networking.firewall = mkIf cfg.openFirewall {
62 allowedTCPPorts = [ cfg.port ];
65 systemd.services.iperf3 = {
66 description = "iperf3 daemon";
67 unitConfig.Documentation = "man:iperf3(1) https://iperf.fr/iperf-doc.php";
68 wantedBy = [ "multi-user.target" ];
69 after = [ "network.target" ];
72 Restart = "on-failure";
75 PrivateDevices = true;
76 CapabilityBoundingSet = "";
77 NoNewPrivileges = true;
79 ${pkgs.iperf3}/bin/iperf \
81 --port ${toString cfg.port} \
82 ${optionalString (cfg.affinity != null) "--affinity ${toString cfg.affinity}"} \
83 ${optionalString (cfg.bind != null) "--bind ${cfg.bind}"} \
84 ${optionalString (cfg.rsaPrivateKey != null) "--rsa-private-key-path ${cfg.rsaPrivateKey}"} \
85 ${optionalString (cfg.authorizedUsersFile != null) "--authorized-users-path ${cfg.authorizedUsersFile}"} \
86 ${optionalString cfg.verbose "--verbose"} \
87 ${optionalString cfg.debug "--debug"} \
88 ${optionalString cfg.forceFlush "--forceflush"} \
89 ${escapeShellArgs cfg.extraFlags}
95 options.services.iperf3 = api;
96 config = mkIf cfg.enable imp;