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";
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")
];
};
}));