Make sync providers distinguishable
This commit is contained in:
parent
b781eb7e08
commit
c4926df9f6
|
@ -17,6 +17,7 @@ let
|
|||
|
||||
mkProvider =
|
||||
{
|
||||
displayName ? "Custom",
|
||||
secretsScript ? "",
|
||||
environment ? { },
|
||||
config ? { },
|
||||
|
@ -24,7 +25,8 @@ let
|
|||
defaultOptions ? { }
|
||||
}:
|
||||
{ ... }: {
|
||||
inherit
|
||||
inherit
|
||||
displayName
|
||||
secretsScript
|
||||
environment
|
||||
config
|
||||
|
@ -38,7 +40,7 @@ let
|
|||
manual = mkProvider {};
|
||||
};
|
||||
|
||||
syncType = lib.types.submodule (
|
||||
mkSyncType = provider: lib.types.submodule (
|
||||
{ config, name, ... }: {
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
|
@ -55,11 +57,8 @@ let
|
|||
|
||||
providerOptions = lib.mkOption {
|
||||
description = "The options of the sync";
|
||||
type = lib.types.oneOf [
|
||||
(builtins.map
|
||||
(provider: provider.options)
|
||||
syncProviders)
|
||||
];
|
||||
type = lib.types.submodule { inherit (provider config) options; };
|
||||
default = {};
|
||||
};
|
||||
|
||||
systemdDependencies = mkSystemdDependencyOption {
|
||||
|
@ -105,11 +104,12 @@ in {
|
|||
default = {};
|
||||
};
|
||||
|
||||
configs = lib.mkOption {
|
||||
type = lib.types.attrsOf syncType;
|
||||
description = "The synchronizations to set up.";
|
||||
default = {};
|
||||
};
|
||||
configs = (builtins.mapAttrs
|
||||
(name: provider: lib.mkOption {
|
||||
type = lib.types.attrsOf (mkSyncType provider);
|
||||
description = "The ${(provider config).displayName} synchronizations to set up.";
|
||||
})
|
||||
syncProviders);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -148,36 +148,39 @@ in {
|
|||
};
|
||||
} // (
|
||||
lib.attrsets.concatMapAttrs
|
||||
(name: sync:
|
||||
let
|
||||
serviceName = "rclone-sync-${name}";
|
||||
in {
|
||||
${serviceName} = {
|
||||
Unit = {
|
||||
Description = "${sync.type}";
|
||||
};
|
||||
(providerName: configs:
|
||||
lib.attrsets.concatMapAttrs
|
||||
(name: sync:
|
||||
let
|
||||
serviceName = "rclone-${providerName}-sync-${name}";
|
||||
in {
|
||||
${serviceName} = {
|
||||
Unit = {
|
||||
Description = "rclone sync service for ${name} at using ${providerName}";
|
||||
};
|
||||
|
||||
Service = {
|
||||
Environment = lib.mapAttrsToList
|
||||
(key: val: (lib.escapeShellArg "${key}=${val}"))
|
||||
sync.environment;
|
||||
Service = {
|
||||
Environment = lib.mapAttrsToList
|
||||
(key: val: (lib.escapeShellArg "${key}=${val}"))
|
||||
sync.environment;
|
||||
|
||||
ExecStart =
|
||||
let
|
||||
script = pkgs.writeShellScriptBin serviceName ''
|
||||
${sync.secretsScript}
|
||||
bash -c echo hello world
|
||||
'';
|
||||
in
|
||||
(lib.getExe script);
|
||||
};
|
||||
ExecStart =
|
||||
let
|
||||
script = pkgs.writeShellScriptBin serviceName ''
|
||||
${sync.secretsScript}
|
||||
bash -c echo hello world
|
||||
'';
|
||||
in
|
||||
(lib.getExe script);
|
||||
};
|
||||
|
||||
Install = {
|
||||
WantedBy = lib.optional sync.autoStart "${targetName}.target";
|
||||
After = builtins.concatLists(builtins.attrValues sync.systemdDependencies);
|
||||
Install = {
|
||||
WantedBy = lib.optional sync.autoStart "${targetName}.target";
|
||||
After = builtins.concatLists(builtins.attrValues sync.systemdDependencies);
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
})
|
||||
configs)
|
||||
cfg.configs);
|
||||
|
||||
targets.${targetName} = {
|
||||
|
|
Loading…
Reference in a new issue