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, ... }:
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,8 +103,35 @@ 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 = {
Description = "rclone Mounts";