syncthing.nix (3277B)
1 { config, lib, pkgs, ... }: 2 3 with lib; 4 let 5 # unstable = versionOlder config.system.nixos.release "21.05"; 6 cfg = config.modules.services.syncthing; 7 isCurrentHost = n: v: n != config.networking.hostName; 8 devices = { 9 wakasu = { 10 id = "3P5BRF6-27NH2OX-3ZUI7EZ-BP4KCSE-EF2GMJL-DHUGPP2-OGHIJVO-LAJOMA7"; 11 addresses = [ "tcp://wakasu.home" "tcp://wakasu.vpn" ]; 12 }; 13 aomi = { 14 id = "XCR6WWB-OZUDGFB-LQPFW73-MV5SPJK-4IGOMA4-IAXON3I-C6OFETL-TPK5FQS"; 15 addresses = [ "tcp://aomi.vpn" "tcp://aomi.home" ]; 16 }; 17 sakhalin = { 18 id = "4TYYG7V-A67D5SN-HMEJCI7-POOZRLL-RNCIE4U-ZYVGTOB-JQ5DOSV-ZCGWUAL"; 19 addresses = [ "tcp://sakhalin.home" "tcp://sakhalin.vpn" ]; 20 }; 21 shikoku = { 22 id = "KZMMXRR-UINDQTS-H3TV2W7-EIGOUDI-3LW4ZDG-7PRKDFV-MJ5KUTJ-YG5Y5AI"; 23 addresses = [ "tcp://shikoku.home" "tcp://shikoku.vpn" ]; 24 }; 25 okinawa = { 26 id = "2RWT47Z-UGSH4QO-G4W6XN7-3XY722R-ZKGDN5U-4MDGHMA-6SM26QM-7VCQIAZ"; 27 addresses = [ "tcp://okinawa.home" "tcp://okinawa.vpn" ]; 28 }; 29 # Deprecated 30 naruhodo = { 31 id = "BKZN3FH-KRP4XRN-XFEVCCG-VANAUJN-YFAUS5Q-WUOLQQ7-II7I6PR-NVJZXQT"; 32 addresses = [ "tcp://naruhodo.vpn" "tcp://naruhodo.home" ]; 33 }; 34 }; 35 deviceNames = builtins.attrNames (filterAttrs isCurrentHost devices); 36 in 37 { 38 options = { 39 modules.services.syncthing = { 40 enable = mkEnableOption "Enable syncthing profile"; 41 guiAddress = mkOption { 42 type = types.str; 43 default = "127.0.0.1:8384"; 44 description = '' 45 The address to serve the web interface at. 46 ''; 47 }; 48 }; 49 }; 50 config = mkIf cfg.enable { 51 services.syncthing = 52 if (builtins.hasAttr "devices" config.services.syncthing) 53 then { 54 enable = true; 55 user = "vincent"; 56 dataDir = "/home/vincent/.syncthing"; 57 configDir = "/home/vincent/.syncthing"; 58 guiAddress = cfg.guiAddress; 59 settings = { 60 devices = filterAttrs isCurrentHost devices; 61 folders = { 62 "/home/vincent/sync" = { 63 label = "sync"; 64 id = "7dshg-r8zr6"; 65 devices = deviceNames; 66 }; 67 "/home/vincent/desktop/notes" = { 68 label = "notes"; 69 id = "q2eld-jylbu"; 70 devices = deviceNames; 71 }; 72 "/home/vincent/desktop/org" = { 73 label = "org"; 74 id = "sjpsr-xfwdu"; 75 devices = deviceNames; 76 }; 77 "/home/vincent/desktop/documents" = { 78 label = "documents"; 79 id = "oftdb-t5anv"; 80 devices = deviceNames; 81 }; 82 "/home/vincent/desktop/pictures/screenshots" = { 83 label = "screenshots"; 84 id = "prpsz-azlz9"; 85 devices = deviceNames; 86 }; 87 "/home/vincent/desktop/pictures/wallpapers" = { 88 label = "wallpapers"; 89 id = "wpiah-ydwwx"; 90 devices = deviceNames; 91 }; 92 }; 93 }; 94 } 95 else { 96 enable = true; 97 user = "vincent"; 98 dataDir = "/home/vincent/.syncthing"; 99 configDir = "/home/vincent/.syncthing"; 100 guiAddress = cfg.guiAddress; 101 }; 102 }; 103 }