PriceBot/module.nix

93 lines
2.6 KiB
Nix
Raw Normal View History

2022-06-19 12:18:06 -07:00
pricebot:
{ config, lib, pkgs, ... }:
2022-06-17 11:24:48 -07:00
with lib;
let
cfg = config.fudo.pricebot;
botJobOpts = { name, ... }: {
options = with types; {
mattermost-channel-id = mkOption {
type = str;
description = "Channel ID in which to post updates.";
};
currency = mkOption {
type = str;
description = "Cryptocurrency to watch for price changes.";
default = name;
};
notify-user = mkOption {
type = str;
description = "Mattermost username to notify of important events.";
};
};
};
in {
options.fudo.pricebot = with types; {
enable = mkEnableOption "Enable PriceBot.";
exchange-host = mkOption {
type = str;
description = "Coinbase Pro host to contact for prices.";
default = "api.exchange.coinbase.com";
};
mattermost-url = mkOption {
type = str;
description = "Mattermost host on which to emit price notifications.";
};
mattermost-auth-token-file = mkOption {
type = str;
description =
"File (on the local system) in which to find the auth token to pass to Mattermost.";
};
monitors = mkOption {
type = attrsOf (submodule botJobOpts);
description = "Map of currency to notify options.";
default = { };
};
};
config = {
systemd.services = mapAttrs' (currency: opts:
nameValuePair "pricebot-${currency}" {
2022-06-19 13:16:51 -07:00
description = "PriceBot for watching and reporting ${currency} prices";
2022-06-17 11:24:48 -07:00
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
environment = {
PRICEBOT_EXCHANGE_HOST = cfg.exchange-host;
PRICEBOT_BEBOT_URL = cfg.mattermost-url;
2022-06-19 15:11:51 -07:00
# PRICEBOT_BEBOT_AUTH_TOKEN_FILE = "%d/auth.token";
PRICEBOT_BEBOT_AUTH_TOKEN_FILE = "FUCKOFF";
2022-06-17 11:24:48 -07:00
PRICEBOT_BEBOT_CHANNEL_ID = opts.mattermost-channel-id;
PRICEBOT_TARGET_CURRENCY = opts.currency;
PRICEBOT_NOTIFY_USER = opts.notify-user;
};
serviceConfig = {
2022-06-19 12:11:44 -07:00
ExecStart = "${pricebot}/bin/pricebot";
2022-06-17 11:24:48 -07:00
DynamicUser = true;
PrivateTmp = true;
PrivateDevices = true;
ProtectSystem = "strict";
ProtectControlGroups = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectHostname = true;
ProtectHome = true;
ProtectClock = true;
ProtectKernelLogs = true;
Restart = "always";
StandardOutput = "journal";
};
unitConfig = {
LoadCredential = "auth.token:${cfg.mattermost-auth-token-file}";
};
2022-06-17 11:24:48 -07:00
}) cfg.monitors;
};
}