home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

syncthing.nix (2459B)


      1 { config, lib, pkgs, ... }:
      2 
      3 with lib;
      4 let
      5   unstable = versionOlder config.system.nixos.release "21.05";
      6   cfg = config.profiles.syncthing;
      7   isCurrentHost = n: v: n != config.networking.hostName;
      8   devices = {
      9     aomi = {
     10       id = "WAD7GYV-RXIL3V3-OT5PFZH-NRQHZWV-D3TGJVR-G4IANXZ-HTO5VT7-XE2WIQQ";
     11       addresses = [ "tcp://aomi.vpn" "tcp://aomi.home" ];
     12     };
     13     naruhodo = {
     14       id = "VTIA5EJ-X2BAMN6-LSBUFVJ-EZ35MTN-AOCEQEZ-HMY7CGV-STVVFTT-5U7SIAY";
     15       addresses = [ "tcp://naruhodo.vpn" "tcp://naruhodo.home" ];
     16       # addresses = [ "tcp://192.168.1.2" "tcp://void.home" ];
     17     };
     18     sakhalin = {
     19       id = "4TYYG7V-A67D5SN-HMEJCI7-POOZRLL-RNCIE4U-ZYVGTOB-JQ5DOSV-ZCGWUAL";
     20       addresses = [ "tcp://sakhalin.home" "tcp://sakhalin.vpn" ];
     21     };
     22     wakasu = {
     23       id = "XNCACMA-LMIZPRZ-J6LEMR5-BVI7IVQ-6HWWMUU-QUCA63X-ZE32NOP-QFDDGQM";
     24       addresses = [ "tcp://wakasu.home" "tcp://wakasu.vpn" ];
     25     };
     26   };
     27   deviceNames = builtins.attrNames (filterAttrs isCurrentHost devices);
     28 in
     29 {
     30   options = {
     31     profiles.syncthing = {
     32       enable = mkEnableOption "Enable syncthing profile";
     33     };
     34   };
     35   config = mkIf cfg.enable {
     36     services.syncthing =
     37       if (builtins.hasAttr "devices" config.services.syncthing)
     38       then {
     39         enable = true;
     40         user = "vincent";
     41         dataDir = "/home/vincent/.syncthing";
     42         configDir = "/home/vincent/.syncthing";
     43         devices = filterAttrs isCurrentHost devices;
     44         folders = {
     45           "/home/vincent/sync" = {
     46             label = "sync";
     47             id = "7dshg-r8zr6";
     48             devices = deviceNames;
     49           };
     50           "/home/vincent/desktop/org" = {
     51             label = "org";
     52             id = "sjpsr-xfwdu";
     53             devices = deviceNames;
     54           };
     55           "/home/vincent/desktop/documents" = {
     56             label = "documents";
     57             id = "oftdb-t5anv";
     58             devices = deviceNames;
     59           };
     60           "/home/vincent/desktop/pictures/screenshots" = {
     61             label = "screenshots";
     62             id = "prpsz-azlz9";
     63             devices = deviceNames;
     64           };
     65           "/home/vincent/desktop/pictures/wallpapers" = {
     66             label = "wallpapers";
     67             id = "wpiah-ydwwx";
     68             devices = deviceNames;
     69           };
     70         };
     71       }
     72       else {
     73         enable = true;
     74         user = "vincent";
     75         dataDir = "/home/vincent/.syncthing";
     76         configDir = "/home/vincent/.syncthing";
     77       };
     78   };
     79 }