system/roles/opia/archive.nix (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | {
config,
lib,
pkgs,
...
}:
let
domain = "opia.ovh";
subdomain = "archive";
# pkg = pkgs.tg-archive;
# format = pkgs.formats.yaml { };
# groups = {
# main = (-1002285871016);
# };
# # see https://github.com/knadh/tg-archive/blob/master/tgarchive/example/config.yaml
# genCfg = name: group: {
# inherit group;
# download_media = true;
# download_avatars = true;
# avatar_size = [
# 64
# 64
# ];
# media_dir = "media";
# media_mime_types = [ ];
# proxy = {
# enable = false;
# };
# fetch_batch_size = 2000;
# fetch_wait = 5;
# fetch_limit = 0;
# publish_dir = "${config.users.users.archive.home}/sites/${name}";
# static_dir = "static";
# per_page = 500;
# show_day_index = true;
# telegram_url = "https://t.me/{id}";
# show_sender_fullname = false;
# timezone = "Europe/Berlin";
# publish_rss_feed = false;
# rss_feed_entries = 100;
# site_url = "https://${subdomain}.${domain}";
# site_name = "@{group} - Telegram group archive";
# site_description = "Public archive of Telegram messages.";
# meta_description = "@{group} {date} - Telegram message archive.";
# page_title = "Page {page} - {date} @{group} Telegram message archive.";
# };
# genScript =
# name: group:
# let
# cfgFile = format.generate "tg-archive.yaml" (genCfg name group);
# dir = "data/${name}";
# in
# ''
# if test ! -d "${dir}"
# then
# ${lib.getExe pkg} --config ${cfgFile} --new --path ${dir}
# fi
# cd "${dir}"
# ${lib.getExe pkg} --config ${cfgFile} --sync
# ${lib.getExe pkg} --config ${cfgFile} --build
# '';
in
{
age.secrets.tg_archive.file = ../../../secrets/tg_archive.age;
users.groups.tg-archive = { };
users.users.tg-archive = {
home = "/var/lib/tg-archive";
createHome = true;
isSystemUser = true;
group = "tg-archive";
extraGroups = [ "caddy" ];
};
# TODO telethon build failure
# environment.systemPackages = [ pkgs.tg-archive ];
# systemd.services.tg-archive = {
# description = "Telegram Archive";
# serviceConfig = {
# Type = "oneshot";
# WorkingDirectory = config.users.users.archive.home;
# EnvironmentFile = [ config.age.secrets.tg_archive.path ];
# User = "archive";
# Group = "archive";
# };
# preStart = ''
# if test ! -d data
# then
# mkdir data
# fi
# cd data
# '';
# script = lib.concatMapAttrsStringSep "\n" genScript groups;
# };
services.caddy.virtualHosts = {
"${subdomain}.${domain}" = {
extraConfig = ''
tls {
dns_challenge_override_domain _acme-challenge.${subdomain}.opia.${config.networking.domain}
}
encode
root ${config.users.users.tg-archive.home}/data
file_server browse
'';
};
};
}
|