Allow specifying custom envs and secrets for providers
This commit is contained in:
parent
5b9d42cdc0
commit
d5a2a06fde
1 changed files with 44 additions and 3 deletions
|
@ -1,8 +1,17 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
mkProvider =
|
||||
{ secretLoader ? ({ ... }: ""), envLoader ? ({ ... }: { }), options ? {}, ... }: {
|
||||
inherit
|
||||
secretLoader
|
||||
envLoader
|
||||
options
|
||||
;
|
||||
};
|
||||
|
||||
syncProviders = {
|
||||
nextcloud = {};
|
||||
proton = {};
|
||||
nextcloud = mkProvider {};
|
||||
proton = mkProvider {};
|
||||
};
|
||||
|
||||
syncType = lib.types.submodule (
|
||||
|
@ -39,6 +48,11 @@ let
|
|||
default = [];
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
environment = syncProviders.${config.type}.envLoader config;
|
||||
secretsScript = syncProviders.${config.type}.secretLoader config;
|
||||
};
|
||||
});
|
||||
in {
|
||||
options = {
|
||||
|
@ -89,7 +103,34 @@ in {
|
|||
(lib.getExe script);
|
||||
};
|
||||
};
|
||||
};
|
||||
} // (
|
||||
lib.attrsets.concatMapAttrs
|
||||
(name: sync:
|
||||
let
|
||||
serviceName = "rclone-sync-${name}";
|
||||
in {
|
||||
${serviceName} = {
|
||||
Unit = {
|
||||
Description = "${sync.type}";
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
};
|
||||
})
|
||||
cfg.configs);
|
||||
|
||||
targets.rclone = {
|
||||
Unit = {
|
||||
|
|
Loading…
Reference in a new issue