Make sync providers distinguishable

This commit is contained in:
Manuel Thalmann 2024-05-15 15:54:03 +02:00
parent b781eb7e08
commit c4926df9f6

View file

@ -17,6 +17,7 @@ let
mkProvider = mkProvider =
{ {
displayName ? "Custom",
secretsScript ? "", secretsScript ? "",
environment ? { }, environment ? { },
config ? { }, config ? { },
@ -25,6 +26,7 @@ let
}: }:
{ ... }: { { ... }: {
inherit inherit
displayName
secretsScript secretsScript
environment environment
config config
@ -38,7 +40,7 @@ let
manual = mkProvider {}; manual = mkProvider {};
}; };
syncType = lib.types.submodule ( mkSyncType = provider: lib.types.submodule (
{ config, name, ... }: { { config, name, ... }: {
options = { options = {
type = lib.mkOption { type = lib.mkOption {
@ -55,11 +57,8 @@ let
providerOptions = lib.mkOption { providerOptions = lib.mkOption {
description = "The options of the sync"; description = "The options of the sync";
type = lib.types.oneOf [ type = lib.types.submodule { inherit (provider config) options; };
(builtins.map default = {};
(provider: provider.options)
syncProviders)
];
}; };
systemdDependencies = mkSystemdDependencyOption { systemdDependencies = mkSystemdDependencyOption {
@ -105,11 +104,12 @@ in {
default = {}; default = {};
}; };
configs = lib.mkOption { configs = (builtins.mapAttrs
type = lib.types.attrsOf syncType; (name: provider: lib.mkOption {
description = "The synchronizations to set up."; type = lib.types.attrsOf (mkSyncType provider);
default = {}; description = "The ${(provider config).displayName} synchronizations to set up.";
}; })
syncProviders);
}; };
}; };
@ -147,14 +147,16 @@ in {
}; };
}; };
} // ( } // (
lib.attrsets.concatMapAttrs
(providerName: configs:
lib.attrsets.concatMapAttrs lib.attrsets.concatMapAttrs
(name: sync: (name: sync:
let let
serviceName = "rclone-sync-${name}"; serviceName = "rclone-${providerName}-sync-${name}";
in { in {
${serviceName} = { ${serviceName} = {
Unit = { Unit = {
Description = "${sync.type}"; Description = "rclone sync service for ${name} at using ${providerName}";
}; };
Service = { Service = {
@ -178,6 +180,7 @@ in {
}; };
}; };
}) })
configs)
cfg.configs); cfg.configs);
targets.${targetName} = { targets.${targetName} = {