nixos/modules/services/rsshub.nix

83 lines
3.2 KiB
Nix
Raw Normal View History

2023-08-23 13:34:58 +08:00
inputs:
{
2023-09-01 21:05:26 +08:00
options.nixos.services.rsshub = let inherit (inputs.lib) mkOption types; in
{
enable = mkOption { type = types.bool; default = false; };
port = mkOption { type = types.ints.unsigned; default = 5221; };
2023-11-12 17:29:40 +08:00
hostname = mkOption { type = types.nonEmptyStr; default = "rsshub.chn.moe"; };
2023-09-01 21:05:26 +08:00
};
config =
let
inherit (inputs.config.nixos.services) rsshub;
inherit (inputs.lib) mkIf;
inherit (builtins) map listToAttrs toString;
in mkIf rsshub.enable
{
2024-08-29 11:41:25 +08:00
systemd =
2023-09-01 21:05:26 +08:00
{
2024-08-29 11:41:25 +08:00
services.rsshub =
2023-09-01 21:05:26 +08:00
{
2024-08-29 11:41:25 +08:00
description = "rsshub";
after = [ "network.target" "redis-rsshub.service" ];
requires = [ "redis-rsshub.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig =
{
User = inputs.config.users.users.rsshub.name;
Group = inputs.config.users.users.rsshub.group;
EnvironmentFile = inputs.config.sops.templates."rsshub/env".path;
WorkingDirectory = "${inputs.pkgs.localPackages.rsshub}";
ExecStart = "${inputs.pkgs.localPackages.rsshub}/bin/rsshub";
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
};
2024-09-02 01:11:10 +08:00
restartTriggers = [ inputs.config.sops.templates."rsshub/env".content ];
2023-09-01 21:05:26 +08:00
};
2024-08-29 11:41:25 +08:00
tmpfiles.rules = [ "d /var/cache/rsshub 0700 rsshub rsshub" ];
2023-09-01 21:05:26 +08:00
};
sops =
{
templates."rsshub/env".content =
let
placeholder = inputs.config.sops.placeholder;
redis = inputs.config.nixos.services.redis.instances.rsshub;
in
''
PORT=${toString rsshub.port}
CACHE_TYPE=redis
REDIS_URL='redis://:${placeholder."redis/rsshub"}@127.0.0.1:${toString redis.port}'
PIXIV_REFRESHTOKEN='${placeholder."rsshub/pixiv-refreshtoken"}'
YOUTUBE_KEY='${placeholder."rsshub/youtube-key"}'
YOUTUBE_CLIENT_ID='${placeholder."rsshub/youtube-client-id"}'
YOUTUBE_CLIENT_SECRET='${placeholder."rsshub/youtube-client-secret"}'
YOUTUBE_REFRESH_TOKEN='${placeholder."rsshub/youtube-refresh-token"}'
2024-09-01 23:03:07 +08:00
TWITTER_AUTH_TOKEN='${placeholder."rsshub/twitter-auth-token"}'
2024-08-29 11:41:25 +08:00
XDG_CONFIG_HOME='/var/cache/rsshub/chromium'
XDG_CACHE_HOME='/var/cache/rsshub/chromium'
2024-09-03 07:57:36 +08:00
BILIBILI_COOKIE_data0='${placeholder."rsshub/bilibili-cookie"}'
2023-09-01 21:05:26 +08:00
'';
secrets = (listToAttrs (map (secret: { name = "rsshub/${secret}"; value = {}; })
[
"pixiv-refreshtoken"
"youtube-key" "youtube-client-id" "youtube-client-secret" "youtube-refresh-token"
2024-09-01 23:03:07 +08:00
"twitter-auth-token"
2024-09-03 07:57:36 +08:00
"bilibili-cookie"
2023-09-01 21:05:26 +08:00
]));
};
2023-12-09 20:01:50 +08:00
users =
{
2024-03-19 20:12:16 +08:00
users.rsshub = { uid = inputs.config.nixos.user.uid.rsshub; group = "rsshub"; isSystemUser = true; };
groups.rsshub.gid = inputs.config.nixos.user.gid.rsshub;
2023-12-09 20:01:50 +08:00
};
2023-09-01 21:05:26 +08:00
nixos.services =
{
redis.instances.rsshub.port = 7116;
nginx =
{
enable = true;
2023-11-09 22:19:37 +08:00
https.${rsshub.hostname}.location."/".proxy.upstream = "http://127.0.0.1:${toString rsshub.port}";
2023-09-01 21:05:26 +08:00
};
};
};
2023-08-23 13:34:58 +08:00
}