Refactor config creation

This commit is contained in:
Manuel Thalmann 2024-05-16 01:04:09 +02:00
parent 8653798a3d
commit 8da71a0b9e

View file

@ -6,7 +6,7 @@ let
owncloudVendor = "owncloud"; owncloudVendor = "owncloud";
owncloudName = "Owncloud"; owncloudName = "Owncloud";
nextcloudVendor = "nextcloud"; nextcloudVendor = "nextcloud";
mkIfNotNull = value: result: lib.mkIf (value != null) result; mkIfNotNull = value: name: lib.mkIf (value != null) { ${name} = value; };
mkSystemdDependencyOption = mkSystemdDependencyOption =
{ default, global ? false, ... }: lib.mkOption { { default, global ? false, ... }: lib.mkOption {
@ -140,17 +140,16 @@ let
config = { config = {
config = lib.mkMerge [ config = lib.mkMerge [
{ url = config.url; } { url = config.url; }
(mkIfNotNull config.vendor { inherit (config) vendor; }) (mkIfNotNull config.vendor "vendor")
(mkIfNotNull config.username { user = config.username; }) (mkIfNotNull config.username "user")
(mkIfNotNull config.obscuredPassword { pass = config.obscuredPassword; }) (mkIfNotNull config.obscuredPassword "pass")
(mkIfNotNull config.bearerToken { bearer_token = config.bearerToken; }) (mkIfNotNull config.bearerToken "bearer_token")
]; ];
secrets = (lib.optionalAttrs (config.obscuredPasswordFile != null) { secrets = lib.mkMerge [
RCLONE_WEBDAV_PASS = config.obscuredPasswordFile; (mkIfNotNull config.obscuredPasswordFile "RCLONE_WEBDAV_PASS")
}) // (lib.optionalAttrs (config.bearerTokenFile != null) { (mkIfNotNull config.bearerTokenFile "RCLONE_WEBDAV_BEARER_TOKEN")
RCLONE_WEBDAV_BEARER_TOKEN = config.bearerTokenFile; ];
});
}; };
})); }));