From 2c9ac25038067457e39afc75fe5fff7ef4168f57 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Tue, 3 Nov 2026 20:05:32 +0100 Subject: [PATCH 1/4] feat(thegeneralist): add archivr service on /mnt/usb/archivr with tailscale https --- flake.lock | 21 +++++ flake.nix | 5 ++ hosts/thegeneralist/archivr/default.nix | 108 ++++++++++++++++++++++++ hosts/thegeneralist/configuration.nix | 1 + 4 files changed, 135 insertions(+) create mode 100644 hosts/thegeneralist/archivr/default.nix diff --git a/flake.lock b/flake.lock index 18bd614..98d0de7 100644 --- a/flake.lock +++ b/flake.lock @@ -44,6 +44,26 @@ "type": "github" } }, + "archivr": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1793731977, + "narHash": "sha256-sc95sd9Hew6ZegYC2mfcOuDu0O2izzoRPlkMGiN8H3I=", + "owner": "thegeneralist01", + "repo": "archivr", + "rev": "85b3c958bcd99ddc1788be2e7211460ec2683485", + "type": "github" + }, + "original": { + "owner": "thegeneralist01", + "repo": "archivr", + "type": "github" + } + }, "brew-src": { "flake": false, "locked": { @@ -561,6 +581,7 @@ "inputs": { "aerospace-src": "aerospace-src", "agenix": "agenix", + "archivr": "archivr", "crosspost": "crosspost", "fenix": "fenix", "ghostty": "ghostty", diff --git a/flake.nix b/flake.nix index 1e039ae..00aaa5f 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,11 @@ url = "github:thegeneralist01/bookkeeper"; }; + archivr = { + url = "github:thegeneralist01/archivr"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + # Private repo: git+ssh so fetching uses the evaluating user's SSH key (github: would need an access token). # No nixpkgs follows: the worker is built from crosspost's own pinned nixpkgs. crosspost.url = "git+ssh://git@github.com/thegeneralist01/crosspost?ref=main"; diff --git a/hosts/thegeneralist/archivr/default.nix b/hosts/thegeneralist/archivr/default.nix new file mode 100644 index 0000000..0e0703e --- /dev/null +++ b/hosts/thegeneralist/archivr/default.nix @@ -0,0 +1,108 @@ +{ config, pkgs, lib, ... }: +let + domain = "mjr.shorthair-wall.ts.net"; +in +{ + services.archivr-server = { + enable = true; + listenAddress = "127.0.0.1"; + port = 8080; + archives = [ + { + id = "personal"; + label = "Personal"; + path = "/mnt/usb/archivr/.archivr"; + } + ]; + environment = { + ARCHIVR_TWITTER_CREDENTIALS_FILE = "/mnt/usb/archivr/creds.txt"; + }; + }; + + # Ensure data directory ownership and mounts + systemd.services.archivr-data-ownership = { + description = "Prepare archivr permissions on /mnt/usb/archivr and /var/lib/archivr-server"; + unitConfig.RequiresMountsFor = [ "/mnt/usb" ]; + before = [ "archivr-server.service" ]; + wantedBy = [ "archivr-server.service" ]; + serviceConfig.Type = "oneshot"; + script = '' + ${pkgs.coreutils}/bin/mkdir -p /mnt/usb/archivr/.archivr/store/{raw,raw_tweets,structured,temp} /var/lib/archivr-server + ${pkgs.coreutils}/bin/chown -R archivr:archivr /mnt/usb/archivr /var/lib/archivr-server + ${pkgs.coreutils}/bin/chmod -R u=rwX,g=rwX,o=rX /mnt/usb/archivr + ''; + }; + + systemd.services.archivr-server = { + requires = [ "archivr-data-ownership.service" ]; + after = [ "archivr-data-ownership.service" ]; + unitConfig.RequiresMountsFor = [ "/mnt/usb" ]; + }; + + # Tailscale TLS certificate automation for HTTPS + systemd.services.tailscale-cert-mjr = { + description = "Fetch Tailscale TLS certificate for ${domain}"; + after = [ "network-online.target" "tailscaled.service" ]; + wants = [ "network-online.target" "tailscaled.service" ]; + before = [ "nginx.service" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = pkgs.writeShellScript "fetch-tailscale-cert-mjr" '' + set -eu + ${pkgs.coreutils}/bin/mkdir -p /var/lib/acme/${domain} + ${pkgs.tailscale}/bin/tailscale cert \ + --cert-file /var/lib/acme/${domain}/fullchain.pem \ + --key-file /var/lib/acme/${domain}/key.pem \ + ${domain} + ${pkgs.coreutils}/bin/chown -R acme:nginx /var/lib/acme/${domain} + ${pkgs.coreutils}/bin/chmod 0750 /var/lib/acme/${domain} + ${pkgs.coreutils}/bin/chmod 0640 /var/lib/acme/${domain}/* + if ${pkgs.systemd}/bin/systemctl is-active --quiet nginx.service; then + ${pkgs.systemd}/bin/systemctl reload nginx.service || true + fi + ''; + }; + }; + + systemd.timers.tailscale-cert-mjr = { + description = "Daily renewal timer for Tailscale TLS certificate for ${domain}"; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "daily"; + Persistent = true; + }; + }; + + # Nginx reverse proxy with HTTPS + services.nginx.virtualHosts.${domain} = { + forceSSL = true; + sslCertificate = "/var/lib/acme/${domain}/fullchain.pem"; + sslCertificateKey = "/var/lib/acme/${domain}/key.pem"; + + listen = [ + { + addr = "100.108.125.63"; + port = 443; + ssl = true; + } + { + addr = "100.108.125.63"; + port = 80; + } + ]; + + locations."/" = { + proxyPass = "http://127.0.0.1:8080"; + recommendedProxySettings = true; + extraConfig = '' + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + + proxy_buffering off; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + ''; + }; + }; +} diff --git a/hosts/thegeneralist/configuration.nix b/hosts/thegeneralist/configuration.nix index 82113cc..2693263 100644 --- a/hosts/thegeneralist/configuration.nix +++ b/hosts/thegeneralist/configuration.nix @@ -18,6 +18,7 @@ ./archive ./forgejo ./crosspost + ./archivr ]; age.secrets.readlaterBotToken = { From 154fb796050bef0a873fdcf5519adc041fe47552 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:17:50 +0100 Subject: [PATCH 2/4] crosspost: bump worker 2.3.0 (X search, CRM feeds, unrepost, thread steps) --- flake.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 98d0de7..f456879 100644 --- a/flake.lock +++ b/flake.lock @@ -86,11 +86,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1793702207, - "narHash": "sha256-vjEPnY/iMe65658J0+Ad+JCGgHCpJLL48lRlo1C/Hsc=", + "lastModified": 1793737049, + "narHash": "sha256-oAEvG691ErZZIdwao+rAteCNIDoVhzavOdN/rEDEvw4=", "ref": "main", - "rev": "b6ef97512769a317dfb744d5d8e5787c55b2b217", - "revCount": 38, + "rev": "79e804d1cd9e2b8429d9948e882410b0bedb484b", + "revCount": 40, "type": "git", "url": "ssh://git@github.com/thegeneralist01/crosspost" }, From 44167c7ef99983d9db45814914544342ac3cd24a Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:25:54 +0100 Subject: [PATCH 3/4] archivr: reload nginx without blocking from tailscale-cert-mjr (fixes switch deadlock) --- hosts/thegeneralist/archivr/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hosts/thegeneralist/archivr/default.nix b/hosts/thegeneralist/archivr/default.nix index 0e0703e..8f84d37 100644 --- a/hosts/thegeneralist/archivr/default.nix +++ b/hosts/thegeneralist/archivr/default.nix @@ -58,8 +58,9 @@ in ${pkgs.coreutils}/bin/chown -R acme:nginx /var/lib/acme/${domain} ${pkgs.coreutils}/bin/chmod 0750 /var/lib/acme/${domain} ${pkgs.coreutils}/bin/chmod 0640 /var/lib/acme/${domain}/* + # --no-block: this unit is ordered before nginx, so a blocking reload would wait on this very job. if ${pkgs.systemd}/bin/systemctl is-active --quiet nginx.service; then - ${pkgs.systemd}/bin/systemctl reload nginx.service || true + ${pkgs.systemd}/bin/systemctl --no-block reload nginx.service || true fi ''; }; From b8e61fe76a3f1dcceab0bc2bd3bb71407b839453 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:34:50 +0100 Subject: [PATCH 4/4] thegeneralist: start nginx and coredns only once tailscale0 has 100.108.125.63 --- hosts/thegeneralist/configuration.nix | 1 + hosts/thegeneralist/tailscale-ip.nix | 51 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 hosts/thegeneralist/tailscale-ip.nix diff --git a/hosts/thegeneralist/configuration.nix b/hosts/thegeneralist/configuration.nix index 2693263..21fc53c 100644 --- a/hosts/thegeneralist/configuration.nix +++ b/hosts/thegeneralist/configuration.nix @@ -14,6 +14,7 @@ imports = [ ./hardware-configuration.nix ./site.nix + ./tailscale-ip.nix ./cache ./archive ./forgejo diff --git a/hosts/thegeneralist/tailscale-ip.nix b/hosts/thegeneralist/tailscale-ip.nix new file mode 100644 index 0000000..28c44d6 --- /dev/null +++ b/hosts/thegeneralist/tailscale-ip.nix @@ -0,0 +1,51 @@ +# Boot ordering for services that bind this host's Tailscale address directly. +# +# nginx (every vhost: archive, archivr, jellyfin, plex) and coredns listen on +# 100.108.125.63, not on 0.0.0.0. That address only appears on tailscale0 once +# tailscaled has logged in, which happens some seconds AFTER tailscaled.service +# reports "started". Ordering after tailscaled.service is therefore not enough: +# before this unit existed nginx failed 2-3 times per boot with "Cannot assign +# requested address" and only came up through its Restart=always retry loop. +# +# tailscale-ip-ready is a oneshot that blocks until the address is really +# present; nginx and coredns are ordered after it. `wants` (not `requires`): +# if Tailscale never connects the wait times out, the unit fails, and nginx and +# coredns still start and fall back to their own restart loops instead of +# staying down. +# +# Deliberately NOT net.ipv4.ip_nonlocal_bind = 1: that lets every service bind +# any address, so a typo in a listen address would silently stop failing. +{ pkgs, ... }: +let + # Must match the `listen.addr` entries of the nginx vhosts and the coredns `bind` lines. + tailscaleAddress = "100.108.125.63"; +in +{ + systemd.services.tailscale-ip-ready = { + description = "Wait until tailscale0 has ${tailscaleAddress}"; + after = [ "tailscaled.service" ]; + wants = [ "tailscaled.service" ]; + serviceConfig = { + Type = "oneshot"; + # Stays "active" after the check so later start jobs don't re-run the wait. + RemainAfterExit = true; + TimeoutStartSec = "2min"; + }; + script = '' + until ${pkgs.iproute2}/bin/ip -4 -o addr show dev tailscale0 2>/dev/null \ + | ${pkgs.gnugrep}/bin/grep -qF ' ${tailscaleAddress}/'; do + sleep 1 + done + ''; + }; + + systemd.services.nginx = { + after = [ "tailscale-ip-ready.service" ]; + wants = [ "tailscale-ip-ready.service" ]; + }; + + systemd.services.coredns = { + after = [ "tailscale-ip-ready.service" ]; + wants = [ "tailscale-ip-ready.service" ]; + }; +}