From a753254c0ef21af79daa78b1e5abf3b1c5fc0e6d Mon Sep 17 00:00:00 2001 From: ibizaman Date: Sun, 25 Aug 2024 17:45:00 +0200 Subject: [PATCH] add option restic backup args to limit bandwidth usage --- modules/blocks/restic.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/blocks/restic.nix b/modules/blocks/restic.nix index 3ca06f3..534f06c 100644 --- a/modules/blocks/restic.nix +++ b/modules/blocks/restic.nix @@ -106,6 +106,20 @@ let }; }; }; + + limitUploadKiBs = lib.mkOption { + type = lib.types.nullOr lib.types.int; + description = "Limit upload bandwidth to the given KiB/s amount."; + default = null; + example = 8000; + }; + + limitDownloadKiBs = lib.mkOption { + type = lib.types.nullOr lib.types.int; + description = "Limit download bandwidth to the given KiB/s amount."; + default = null; + example = 8000; + }; }; repoSlugName = name: builtins.replaceStrings ["/" ":"] ["_" "_"] (lib.strings.removePrefix "/" name); @@ -188,6 +202,14 @@ in backupCleanupCommand = lib.strings.concatStringsSep "\n" instance.hooks.after_backup; } // lib.attrsets.optionalAttrs (builtins.length instance.excludePatterns > 0) { exclude = instance.excludePatterns; + + extraBackupArgs = + (lib.optionals (instance.limitUploadKiBs != null) [ + "--limit-upload=${toString instance.limitUploadKiBs}" + ]) + ++ (lib.optionals (instance.limitDownloadKiBs != null) [ + "--limit-download=${toString instance.limitDownloadKiBs}" + ]); }; };