From 8da71a0b9efccafd9c262b7bc9800710e1db281a Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 16 May 2024 01:04:09 +0200 Subject: [PATCH] Refactor config creation --- lib/modules/rclone.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/modules/rclone.nix b/lib/modules/rclone.nix index 9c139f6..9e2090f 100644 --- a/lib/modules/rclone.nix +++ b/lib/modules/rclone.nix @@ -6,7 +6,7 @@ let owncloudVendor = "owncloud"; owncloudName = "Owncloud"; nextcloudVendor = "nextcloud"; - mkIfNotNull = value: result: lib.mkIf (value != null) result; + mkIfNotNull = value: name: lib.mkIf (value != null) { ${name} = value; }; mkSystemdDependencyOption = { default, global ? false, ... }: lib.mkOption { @@ -140,17 +140,16 @@ let config = { config = lib.mkMerge [ { url = config.url; } - (mkIfNotNull config.vendor { inherit (config) vendor; }) - (mkIfNotNull config.username { user = config.username; }) - (mkIfNotNull config.obscuredPassword { pass = config.obscuredPassword; }) - (mkIfNotNull config.bearerToken { bearer_token = config.bearerToken; }) + (mkIfNotNull config.vendor "vendor") + (mkIfNotNull config.username "user") + (mkIfNotNull config.obscuredPassword "pass") + (mkIfNotNull config.bearerToken "bearer_token") ]; - secrets = (lib.optionalAttrs (config.obscuredPasswordFile != null) { - RCLONE_WEBDAV_PASS = config.obscuredPasswordFile; - }) // (lib.optionalAttrs (config.bearerTokenFile != null) { - RCLONE_WEBDAV_BEARER_TOKEN = config.bearerTokenFile; - }); + secrets = lib.mkMerge [ + (mkIfNotNull config.obscuredPasswordFile "RCLONE_WEBDAV_PASS") + (mkIfNotNull config.bearerTokenFile "RCLONE_WEBDAV_BEARER_TOKEN") + ]; }; }));