complete-computing-environment/syncthing.org

76 lines
3.7 KiB
Org Mode

:PROPERTIES:
:ID: cce/syncthing
:ROAM_ALIASES: Syncthing
:END:
#+TITLE: Nearly Stateless Computing Using Syncthing
#+filetags: :CCE:Tools:
#+ARCOLOGY_ALLOW_CRAWL: t
#+ARCOLOGY_KEY: cce/syncthing
#+PROPERTY: header-args :mkdirp yes :results none
#+AUTO_TANGLE: t
[[https://syncthing.net/][Syncthing]] is a piece of [[id:35f18b82-0671-405f-9321-6bf442e5c8f6][Free Software]] designed to ... sync ... things. It's a peer-to-peer file syncronization tool which I run on nearly every computer I own to sync collections of files between online devices in nearly real-time. This has allowed me to increasingly treat my endpoint machines, my laptop, my GPD Pocket, etc as fungible, nearly stateless machines, at the cost of making [[id:47ff77f9-3eae-43eb-886c-7513d05f047f][Secure Backup Infrastructure]] slightly more difficult, I off-set this on [[id:c75d20e6-8888-4c5a-ac97-5997e2f1c711][NixOS]] with local ZFS rollbacks for data loss scenarios.
I have a lot of data exposed in my Syncthing; this laptop, with my entire Music and Photo libraries on it, as well as all of my Code, this Wiki, and some upload-only directories, I am managing 500GiB of data via Syncthing. My server has yet more folders managed by Syncthing. It makes [[id:357afb90-1121-43c3-94a1-4ecd43e3b9fe][Bootstrapping A Laptop with the CCE]] easier, it lets me take more daring steps to harden and grow my environment. Once this whole experiment integrating CCE in to my wiki is done, I'll probably be able to simplify my bootstrap even further.
Syncthing is installed with [[id:cce/home-manager][home-manager]], and bootstrapped manually, copying IDs around in some way. it's a bit of a pain and i'd like to have a better configuration generator some day, or at least documentation of this bootstrap process...
This is straightforward; [[id:20230220T220556.588418][Syncthing Tray]] is installed elsewhere.
#+ARROYO_HOME_MODULE: hm/syncthing.nix
#+begin_src nix :tangle ~/arroyo-nix/hm/syncthing.nix
{ lib, pkgs, ...}:
{
services.syncthing.enable = true;
services.syncthing.extraOptions = ["--gui-address=http://0.0.0.0:8384"];
}
#+end_src
I poke a hole in the firewall in [[id:cce/my_nixos_configuration][My NixOS configuration]]:
#+ARROYO_NIXOS_MODULE: nixos/syncthing.nix
#+ARROYO_SYSTEM_EXCLUDE: droid
#+begin_src nix :tangle ~/arroyo-nix/nixos/syncthing.nix
{ ... }:
{
networking.firewall.allowedTCPPorts = [ 22000 ];
networking.firewall.interfaces.tailscale0.allowedTCPPorts = [ 8384 ];
}
#+end_src
* Dealing with Syncthing Conflicts
:PROPERTIES:
:ID: 20230111T141211.153590
:END:
I have some functions which help deal with conflicts:
#+ARROYO_EMACS_MODULE: syncthing
#+begin_src emacs-lisp :tangle ~/org/cce/syncthing.el
(defun cce/syncthing-deconflict--possible-pairs (dir)
(->> (f-directories dir)
(append (list dir))
(--map (or (f-glob "*sync-conflict*.org" it)
(f-glob "*sync-conflict*.nix" it)))
(-flatten)
(--map (list it (replace-regexp-in-string (rx (seq (literal ".sync-conflict") (one-or-more (not ".")) )) "" it)))))
(defun cce/syncthing-deconflict (&optional dir)
(interactive "D")
(let* ((dir (or dir org-roam-directory))
(possible-pairs (cce/syncthing-deconflict--possible-pairs dir))
(stale-conflict-files ; source doesn't exist or was moved elsewhere.
(--remove (file-exists-p (second it)) possible-pairs))
(ediff-candidates ; source does exist and should be ediff'd
(--filter (file-exists-p (second it)) possible-pairs)))
(dolist (f stale-conflict-files)
(when (yes-or-no-p (format "%s does not exist. Delete %s? " (second f) (first f)))
(delete-file (first f))))
(dolist (f ediff-candidates)
(apply #'ediff-files f))))
(provide 'cce/syncthing)
#+end_src