Allow specifying custom envs and secrets for providers

This commit is contained in:
Manuel Thalmann 2024-05-14 15:24:17 +02:00
parent 5b9d42cdc0
commit d5a2a06fde

View file

@ -1,8 +1,17 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
mkProvider =
{ secretLoader ? ({ ... }: ""), envLoader ? ({ ... }: { }), options ? {}, ... }: {
inherit
secretLoader
envLoader
options
;
};
syncProviders = { syncProviders = {
nextcloud = {}; nextcloud = mkProvider {};
proton = {}; proton = mkProvider {};
}; };
syncType = lib.types.submodule ( syncType = lib.types.submodule (
@ -39,6 +48,11 @@ let
default = []; default = [];
}; };
}; };
config = {
environment = syncProviders.${config.type}.envLoader config;
secretsScript = syncProviders.${config.type}.secretLoader config;
};
}); });
in { in {
options = { options = {
@ -89,8 +103,35 @@ in {
(lib.getExe script); (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 = { targets.rclone = {
Unit = { Unit = {
Description = "rclone Mounts"; Description = "rclone Mounts";