import opia roles
1 file changed, 124 insertions(+), 0 deletions(-)
changed files
A system/roles/opia/archive.nix
@@ -0,0 +1,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 + ''; + }; + }; +}