forked from
tangled.org/core
Monorepo for Tangled
1{
2 config,
3 pkgs,
4 lib,
5 ...
6}: let
7 cfg = config.services.tangled.knotmirror;
8in with lib; {
9 options.services.tangled.knotmirror = {
10 enable = mkOption {
11 type = types.bool;
12 default = false;
13 description = "Enable a tangled knot";
14 };
15
16 package = mkOption {
17 type = types.package;
18 description = "Package to use for the knotmirror";
19 };
20
21 tap-package = mkOption {
22 type = types.package;
23 description = "tap package to use for the knotmirror";
24 };
25
26 listenAddr = mkOption {
27 type = types.str;
28 default = "0.0.0.0:7000";
29 description = "Address to listen on";
30 };
31
32 hostname = mkOption {
33 type = types.str;
34 example = "my.knotmirror.com";
35 description = "Hostname for the server (required)";
36 };
37
38 dbUrl = mkOption {
39 type = types.str;
40 example = "postgresql://...";
41 description = "Database URL. postgresql expected (required)";
42 };
43
44 atpPlcUrl = mkOption {
45 type = types.str;
46 default = "https://plc.directory";
47 description = "atproto PLC directory";
48 };
49
50 atpRelayUrl = mkOption {
51 type = types.str;
52 default = "https://relay1.us-east.bsky.network";
53 description = "atproto relay";
54 };
55
56 fullNetwork = mkOption {
57 type = types.bool;
58 default = false;
59 description = "Whether to automatically mirror from entire network";
60 };
61 };
62 config = mkIf cfg.enable {
63 environment.systemPackages = [
64 pkgs.git
65 cfg.package
66 ];
67
68 systemd.services.knotmirror-tap = {
69 description = "knotmirror tap service";
70 after = ["network.target"];
71 wantedBy = ["multi-user.target"];
72 serviceConfig = {
73 LogsDirectory = "knotmirror-tap";
74 StateDirectory = "knotmirror-tap";
75 Environment = [
76 "TAP_BIND=:2480"
77 "TAP_PLC_URL=${cfg.atpPlcUrl}"
78 "TAP_RELAY_URL=${cfg.atpRelayUrl}"
79 "TAP_DATABASE_URL=sqlite:///var/lib/knotmirror-tap/tap.db"
80 "TAP_RETRY_TIMEOUT=30s"
81 "TAP_COLLECTION_FILTERS=sh.tangled.repo"
82 (if cfg.fullNetwork then
83 "TAP_SIGNAL_COLLECTION=sh.tangled.repo"
84 else
85 "TAP_FULL_NETWORK=false")
86 ];
87 ExecStart = "${getExe cfg.tap-package} run";
88 };
89 };
90
91 systemd.services.knotmirror = {
92 description = "knotmirror service";
93 after = ["network.target" "postgresql.service"];
94 wantedBy = ["multi-user.target"];
95 path = [
96 pkgs.git
97 ];
98 serviceConfig = {
99 LogsDirectory = "knotmirror";
100 StateDirectory = "knotmirror";
101 Environment = [
102 # TODO: add environment variables
103 "MIRROR_LISTEN=${cfg.listenAddr}"
104 "MIRROR_HOSTNAME=${cfg.hostname}"
105 "MIRROR_TAP_URL=http://localhost:2480"
106 "MIRROR_DB_URL=${cfg.dbUrl}"
107 "MIRROR_GIT_BASEPATH=/var/lib/knotmirror/repos"
108 "MIRROR_KNOT_USE_SSL=true"
109 "MIRROR_KNOT_SSRF=true"
110 "MIRROR_RESYNC_PARALLELISM=12"
111 "MIRROR_METRICS_LISTEN=:7100"
112 "MIRROR_SLURPER_CONCURRENCY=4"
113 ];
114 ExecStart = "${getExe cfg.package} serve";
115 Restart = "always";
116 };
117 };
118 };
119}