This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / configs / syncthing.nix
2.7 kB 102 lines
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 9 shares = { 10 "/home/lass/sync" = [ 11 "mors" 12 "green" 13 "coaxmetal" 14 "ignavia" 15 ]; # TODO add aergia 16 "/home/lass/tmp/the_playlist" = [ 17 "mors" 18 "radio" 19 ]; 20 # "/home/lass/.weechat" = [ "green" "mors" ]; 21 "/home/lass/decsync" = [ 22 "mors" 23 "green" 24 "massulus" 25 "massulus2" 26 ]; 27 }; 28 29 machine_peers = lib.foldr ( 30 host: acc: 31 let 32 syncthing_id_path = 33 config.clan.core.settings.directory + "/vars/per-machine/${host}/syncthing/syncthing.pub/value"; 34 in 35 if builtins.pathExists syncthing_id_path then 36 acc 37 // { 38 ${host}.id = lib.removeSuffix "\n" (builtins.readFile syncthing_id_path); 39 } 40 else 41 acc 42 ) { } (lib.attrNames (builtins.readDir ../machines)); 43 44 all_peers = machine_peers // { 45 "massulus".id = "R2EGJ5S-PQMETUP-C2UGXQG-A6VP7TB-NGSN3MV-C7OGSWT-SZ34L3X-H6IF6AQ"; 46 "massulus2".id = "OTJBJNO-VHBCVDL-QSELUS7-S6JDMYR-7WLE36A-6XSRSLP-VKYOYJJ-AHFGZAG"; 47 }; 48 49 used_peer_names = lib.unique ( 50 lib.filter lib.isString ( 51 lib.flatten (lib.mapAttrsToList (_n: v: v.devices) config.services.syncthing.settings.folders) 52 ) 53 ); 54 used_peers = lib.filterAttrs (n: _v: lib.elem n used_peer_names) all_peers; 55in 56{ 57 services.syncthing = { 58 enable = true; 59 group = "syncthing"; 60 configDir = "/var/lib/syncthing"; 61 key = config.clan.core.vars.generators.syncthing.files."syncthing.key".path; 62 cert = config.clan.core.vars.generators.syncthing.files."syncthing.cert".path; 63 settings.devices = used_peers; 64 settings.folders = lib.mapAttrs (share: devices: { 65 enable = lib.elem config.networking.hostName devices; 66 path = share; 67 ignorePerms = false; 68 versioning = { 69 type = "trashcan"; 70 params = { 71 cleanoutDays = "30"; 72 }; 73 }; 74 # Filter devices to only include those that exist in all_peers 75 devices = lib.filter (device: all_peers ? ${device}) devices; 76 }) shares; 77 user = "lass"; 78 }; 79 80 clan.core.vars.generators.syncthing = { 81 files."syncthing.key" = { }; 82 files."syncthing.cert" = { }; 83 files."syncthing.pub".secret = false; 84 runtimeInputs = with pkgs; [ 85 coreutils 86 gnugrep 87 syncthing 88 ]; 89 script = '' 90 syncthing generate --config "$out" 91 mv "$out"/key.pem "$out"/syncthing.key 92 mv "$out"/cert.pem "$out"/syncthing.cert 93 cat "$out"/config.xml | grep -oP '(?<=<device id=")[^"]+' | uniq > "$out"/syncthing.pub 94 ''; 95 }; 96 97 boot.kernel.sysctl."fs.inotify.max_user_watches" = 524288; 98 networking.firewall = { 99 allowedTCPPorts = [ 22000 ]; 100 allowedUDPPorts = [ 21027 ]; 101 }; 102}