Monorepo for Tangled tangled.org

nix: add knotmirror module #1167

merged opened by boltless.me targeting master from sl/knotmirror
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mh3qbj6ytm22
+151
Diff #0
+10
flake.nix
··· 350 350 351 351 services.tangled.appview.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.appview; 352 352 }; 353 + nixosModules.knotmirror = { 354 + lib, 355 + pkgs, 356 + ... 357 + }: { 358 + imports = [./nix/modules/knotmirror.nix]; 359 + 360 + services.tangled.knotmirror.tap-package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.tap; 361 + services.tangled.knotmirror.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.knotmirror; 362 + }; 353 363 nixosModules.knot = { 354 364 lib, 355 365 pkgs,
+141
nix/modules/knotmirror.nix
··· 1 + { 2 + config, 3 + pkgs, 4 + lib, 5 + ... 6 + }: let 7 + cfg = config.services.tangled.knotmirror; 8 + in 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 + adminListenAddr = mkOption { 33 + type = types.str; 34 + default = "127.0.0.1:7200"; 35 + description = "Address to listen on"; 36 + }; 37 + 38 + hostname = mkOption { 39 + type = types.str; 40 + example = "my.knotmirror.com"; 41 + description = "Hostname for the server (required)"; 42 + }; 43 + 44 + dbUrl = mkOption { 45 + type = types.str; 46 + example = "postgresql://..."; 47 + description = "Database URL. postgresql expected (required)"; 48 + }; 49 + 50 + atpPlcUrl = mkOption { 51 + type = types.str; 52 + default = "https://plc.directory"; 53 + description = "atproto PLC directory"; 54 + }; 55 + 56 + atpRelayUrl = mkOption { 57 + type = types.str; 58 + default = "https://relay1.us-east.bsky.network"; 59 + description = "atproto relay"; 60 + }; 61 + 62 + fullNetwork = mkOption { 63 + type = types.bool; 64 + default = false; 65 + description = "Whether to automatically mirror from entire network"; 66 + }; 67 + 68 + tap = { 69 + port = mkOption { 70 + type = types.port; 71 + default = 7480; 72 + description = "Internal port to run the knotmirror tap"; 73 + }; 74 + 75 + dbUrl = mkOption { 76 + type = types.str; 77 + default = "sqlite:///var/lib/knotmirror-tap/tap.db"; 78 + description = "database connection string (sqlite://path or postgres://...)"; 79 + }; 80 + }; 81 + }; 82 + config = mkIf cfg.enable { 83 + environment.systemPackages = [ 84 + pkgs.git 85 + cfg.package 86 + ]; 87 + 88 + systemd.services.tap-knotmirror = { 89 + description = "knotmirror tap service"; 90 + after = ["network.target"]; 91 + wantedBy = ["multi-user.target"]; 92 + serviceConfig = { 93 + LogsDirectory = "knotmirror-tap"; 94 + StateDirectory = "knotmirror-tap"; 95 + Environment = [ 96 + "TAP_BIND=:${toString cfg.tap.port}" 97 + "TAP_PLC_URL=${cfg.atpPlcUrl}" 98 + "TAP_RELAY_URL=${cfg.atpRelayUrl}" 99 + "TAP_RESYNC_PARALLELISM=10" 100 + "TAP_DATABASE_URL=${cfg.tap.dbUrl}" 101 + "TAP_RETRY_TIMEOUT=60s" 102 + "TAP_COLLECTION_FILTERS=sh.tangled.repo" 103 + (if cfg.fullNetwork then 104 + "TAP_SIGNAL_COLLECTION=sh.tangled.repo" 105 + else 106 + "TAP_FULL_NETWORK=false") 107 + ]; 108 + ExecStart = "${getExe cfg.tap-package} run"; 109 + }; 110 + }; 111 + 112 + systemd.services.knotmirror = { 113 + description = "knotmirror service"; 114 + after = ["network.target" "tap-knotmirror.service"]; 115 + wantedBy = ["multi-user.target"]; 116 + path = [ 117 + pkgs.git 118 + ]; 119 + serviceConfig = { 120 + LogsDirectory = "knotmirror"; 121 + StateDirectory = "knotmirror"; 122 + Environment = [ 123 + # TODO: add environment variables 124 + "MIRROR_LISTEN=${cfg.listenAddr}" 125 + "MIRROR_HOSTNAME=${cfg.hostname}" 126 + "MIRROR_TAP_URL=http://localhost:${toString cfg.tap.port}" 127 + "MIRROR_DB_URL=${cfg.dbUrl}" 128 + "MIRROR_GIT_BASEPATH=/var/lib/knotmirror/repos" 129 + "MIRROR_KNOT_USE_SSL=true" 130 + "MIRROR_KNOT_SSRF=true" 131 + "MIRROR_RESYNC_PARALLELISM=12" 132 + "MIRROR_METRICS_LISTEN=127.0.0.1:7100" 133 + "MIRROR_ADMIN_LISTEN=${cfg.adminListenAddr}" 134 + "MIRROR_SLURPER_CONCURRENCY=4" 135 + ]; 136 + ExecStart = "${getExe cfg.package} serve"; 137 + Restart = "always"; 138 + }; 139 + }; 140 + }; 141 + }

History

5 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
nix: add knotmirror module
2/3 failed, 1/3 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
nix: add knotmirror module
expand 0 comments
1 commit
expand
nix: add knotmirror module
expand 0 comments
1 commit
expand
nix: add knotmirror module
expand 0 comments
boltless.me submitted #0
1 commit
expand
nix: add knotmirror module
expand 0 comments