rss-webhook-trigger/nix/module.nix

141 lines
3.9 KiB
Nix

{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.rss-webhook-trigger;
format = pkgs.formats.toml {};
configFile = format.generate "trigger.toml" {
inherit (cfg) jwt interval;
feed = cfg.hooks;
};
in {
options.services.rss-webhook-trigger = {
enable = mkEnableOption "Enables the rss-webhook-trigger service";
interval = mkOption {
type = types.int;
default = 1800;
description = "how often to check the feeds for updates";
};
jwt = mkOption {
description = "Configuration for generating JWT authorization tokens";
type = types.nullOr (types.submodule {
options = {
key = mkOption {
type = types.str;
description = "JWT RS256 key";
};
issuer = mkOption {
type = types.str;
description = "JWT issuer";
};
listen = mkOption {
type =
types.either (types.submodule {
options = {
path = mkOption {
type = types.path;
description = "UNIX socket path to listen om";
};
};
}) (types.submodule {
options = {
address = mkOption {
type = types.str;
description = "IP address to listen on";
};
port = mkOption {
type = types.port;
description = "port to listen on";
};
};
});
description = "Serve openid-configuration and JWT keys at the specified address or socket";
default = {path = "/var/run/rss-webhook-trigger/jwt.sock";};
};
};
});
default = null;
};
hooks = mkOption {
description = "Hook configuration";
type = types.listOf (types.submodule {
options = {
feed = mkOption {
type = types.str;
description = "Source feed";
};
hook = mkOption {
type = types.str;
description = "hook url";
};
headers = mkOption {
type = types.attrs;
default = {};
description = "headers to send";
};
body = mkOption {
type = types.attrs;
default = {};
description = "body to send";
};
};
});
default = [];
};
log = mkOption {
type = types.str;
default = "INFO";
description = "Log level";
};
package = mkOption {
type = types.package;
description = "package to use";
};
};
config = mkIf cfg.enable {
systemd.services."rss-webhook-trigger" = {
wantedBy = ["multi-user.target"];
environment = {
RUST_LOG = cfg.log;
};
serviceConfig = {
ExecStart = "${cfg.package}/bin/rss-webhook-trigger ${configFile}";
Restart = "on-failure";
DynamicUser = true;
PrivateTmp = true;
ProtectSystem = "strict";
ProtectHome = true;
NoNewPrivileges = true;
PrivateDevices = true;
ProtectClock = true;
CapabilityBoundingSet = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
SystemCallArchitectures = "native";
ProtectKernelModules = true;
RestrictNamespaces = true;
MemoryDenyWriteExecute = true;
ProtectHostname = true;
LockPersonality = true;
ProtectKernelTunables = true;
RestrictAddressFamilies = ["AF_INET" "AF_INET6" "AF_UNIX"];
RestrictRealtime = true;
ProtectProc = "noaccess";
RuntimeDirectory = "rss-webhook-trigger";
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
IPAddressDeny = "localhost link-local multicast";
};
};
};
}