From e8173f756695d295794d03ab2acb027b42615fcf Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 15 May 2024 09:48:02 +0200 Subject: [PATCH] Add configurations for individual providers --- lib/modules/rclone.nix | 56 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/lib/modules/rclone.nix b/lib/modules/rclone.nix index 239c949..c5194a3 100644 --- a/lib/modules/rclone.nix +++ b/lib/modules/rclone.nix @@ -4,10 +4,17 @@ let targetName = "rclone"; mkProvider = - { secretLoader ? ({ ... }: ""), envLoader ? ({ ... }: { }), options ? {}, ... }: { + { + secretLoader ? ({ ... }: ""), + envLoader ? ({ ... }: { }), + configLoader ? ({ ... }: { }), + options ? {}, + ... + }: { inherit secretLoader envLoader + configLoader options ; }; @@ -24,8 +31,37 @@ let inherit default; }; + mkWebdavOptions = { vendorName }: { + username = lib.mkOption { + type = lib.types.str; + description = "The name of the user to log in to ${vendorName}."; + }; + + password = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "The password for logging in to ${vendorName}."; + }; + + passwordFile = lib.mkOption { + type = lib.types.nullOr (lib.types.either lib.types.path lib.types.str); + description = "A path to a file to read the password from for logging in to ${vendorName}."; + }; + }; + + mkOwncloudOptions = + { vendorName ? "Nextcloud" }: (mkWebdavOptions { inherit vendorName; }) // { + baseUrl = lib.mkOption { + type = lib.types.str; + description = "The base URL of the ${vendorName} server."; + }; + }; + syncProviders = { - nextcloud = mkProvider {}; + nextcloud = mkProvider { + options = lib.types.submodule ( + (mkOwncloudOptions { })); + }; + proton = mkProvider {}; manual = mkProvider {}; }; @@ -45,6 +81,15 @@ let default = true; }; + providerOptions = lib.mkOption { + description = "The options of the sync"; + type = lib.types.oneOf [ + (builtins.map + (provider: provider.options) + syncProviders) + ]; + }; + systemdDependencies = mkSystemdDependencyOption { default = cfg.systemdDependencies; }; @@ -60,11 +105,18 @@ let description = "A script for loading secrets before launching the sync."; default = []; }; + + config = lib.mkOption { + type = lib.types.attrs; + description = "The rclone config to use for creating the mount."; + visible = false; + }; }; config = { environment = syncProviders.${config.type}.envLoader config; secretsScript = syncProviders.${config.type}.secretLoader config; + config = syncProviders.${config.type}.configLoader config; }; }); in {