This repository has no description
0

Configure Feed

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

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