Commit bc6757fb9b1b

Vincent Demeester <vincent@sbr.pm>
2025-04-19 00:26:04
flake & systems: add home syncthing services…
… and try to fix other builds Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent bc6d3a4
Changed files (5)
home/common/services/syncthing.nix
@@ -0,0 +1,68 @@
+{ config
+, lib
+, pkgs
+, outputs
+, ...
+}:
+let
+  isCurrentHost = n: v: n != config.networking.hostName;
+  # Folders list
+  folders = [
+    # TODO maybe deprecate for documents
+    { label = "sync"; id = "7dshg-r8zr6"; }
+    { label = "documents"; id = "oftdb-t5anv"; }
+    { label = "org"; id = "sjpsr-xfwdu"; }
+    { label = "screenshots"; id = "prpsz-azlz9"; }
+    { label = "wallpapers"; id = "wpiah-ydwwx"; }
+    { label = "photos"; id = "uetya-ypa3d"; }
+    { label = "music"; id = "kcyrf-mugzt"; }
+  ];
+  getSyncthingFolders = c:
+    if builtins.hasAttr "syncthingFolders" c._module.specialArgs
+    then
+      c._module.specialArgs.syncthingFolders
+    else
+      [ ];
+  deviceHasFolder = folder: n: v: lib.lists.any (s: s == folder) (getSyncthingFolders v);
+  devicesForFolder = folder: lib.attrsets.filterAttrs (deviceHasFolder folder) outputs.nixosConfigurations;
+  # outputs.nixosConfigurations.$.syncthingFolders will contains the folders for a host
+
+  # non-nixos syncthing machines
+  extras = [
+    # NAS
+    {
+      name = "aion";
+      id = "YORNSGU-UC4IAG5-IWJCD7T-MVPIU7O-AYM36UK-LEHF7AP-CBC4L6C-ZWKUYQF";
+      addresses = [ "tcp://aion.home" "tcp://aion.vpn" "tcp://aion.sbr.pm" ];
+      folders = [ "org" "documents" "sync" "screenshots" "wallpapers" "photos" "videos" ];
+    }
+    # Macbook
+    {
+      name = "honshu";
+      id = "RGIR34D-3SH3GZK-CYPNNFI-5M5I2K4-HVTUS56-72GJTLH-SDMOY4I-I7AURQR";
+      addresses = [ "tcp://honshu.home" "tcp://honshu.sbr.pm" ];
+      folders = [ ];
+    }
+    # Windows Gaming machine
+    {
+      name = "okinawa";
+      id = "2RWT47Z-UGSH4QO-G4W6XN7-3XY722R-ZKGDN5U-4MDGHMA-6SM26QM-7VCQIAZ";
+      addresses = [ "tcp://okinawa.home" "tcp://okinawa.vpn" "tcp://okinawa.sbr.pm" ];
+      folder = [ ];
+    }
+    # iPhone
+    {
+      name = "hokkaido";
+      id = "XD4XYNZ-DT3PJEY-UJYBHWX-6OQPPUI-HTW752L-FYTX3TW-GVHDTKW-PT336QV";
+      folders = [ "org" "music" "documents" "sync" ];
+    }
+  ];
+in
+{
+  services.syncthing = {
+    enable = true;
+    extraOptions = [ "--no-default-folder" ];
+    # guiAddress = cfg.guiAddress;
+    settings = { };
+  };
+}
home/default.nix
@@ -1,6 +1,7 @@
 { config
 , desktop
 , hostname
+, syncthingFolders
 , lib
 , pkgs
 , outputs
@@ -8,7 +9,8 @@
 , username
 , inputs
 , ...
-}: {
+}:
+{
   imports = [
     ./common/shell
   ]
@@ -16,7 +18,8 @@
   ++ lib.optional
     (builtins.pathExists (
       ./. + "/common/users/${username}"
-    )) ./common/users/${username};
+    )) ./common/users/${username}
+  ++ lib.optional ((builtins.length syncthingFolders) > 0) ./common/services/syncthing.nix;
 
   home = {
     inherit username stateVersion;
lib/default.nix
@@ -50,7 +50,7 @@
           stateVersion
           hostname
           desktop
-          # syncthingFolders
+          syncthingFolders
           system
           ;
       };
systems/common/users/vincent.nix
@@ -2,6 +2,7 @@
 , lib
 , config
 , desktop
+, syncthingFolders
 , hostname
 , outputs
 , stateVersion
@@ -68,7 +69,7 @@ in
   # Do I user home-manager nixosModule *or* home-manager on its own
   home-manager.users.vincent =
     (import ../../../home/default.nix {
-      inherit config pkgs lib hostname desktop outputs inputs stateVersion;
+      inherit config pkgs lib hostname syncthingFolders desktop outputs inputs stateVersion;
       username = "vincent";
     });
   # This is a workaround for not seemingly being able to set $EDITOR in home-manager
flake.nix
@@ -92,7 +92,7 @@
               inputs.nixos-hardware.nixosModules.lenovo-thinkpad-x1-9th-gen
               ./systems/hosts/wakasu.nix
             ];
-            syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
+            # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
           };
           aomi = inputs.nixpkgs.lib.nixosSystem {
             system = "x86_64-linux";
@@ -101,7 +101,7 @@
               inputs.nixos-hardware.nixosModules.common-pc-laptop-ssd
               ./systems/hosts/aomi.nix
             ];
-            syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
+            # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
           };
           # Servers (stable)
           shikoku = inputs.nixpkgs-24_11.lib.nixosSystem {
@@ -109,7 +109,7 @@
             modules = commonModules ++ stableModules ++ [
               ./systems/hosts/shikoku.nix
             ];
-            syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
+            # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
           };
           sakhalin = inputs.nixpkgs-24_11.lib.nixosSystem {
             system = "x86_64-linux";
@@ -117,7 +117,7 @@
               inputs.nixos-hardware.nixosModules.common-pc-ssd
               ./systems/hosts/sakhalin.nix
             ];
-            syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
+            # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
           };
           kerkouane = inputs.nixpkgs-24_11.lib.nixosSystem {
             system = "x86_64-linux";
@@ -125,7 +125,7 @@
               ./systems/modules/services/govanityurl.nix
               ./systems/hosts/kerkouane.nix
             ];
-            syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
+            # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
           };
           # carthage = inputs.nixpkgs-24_11.lib.nixosSystem {
           #   system = "aarch64-linux";
@@ -140,7 +140,7 @@
             modules = commonModules ++ stableModules ++ [
               ./systems/hosts/athena.nix
             ];
-            syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
+            # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
           };
           # demeter
           demeter = inputs.nixpkgs-24_11.lib.nixosSystem {
@@ -148,7 +148,7 @@
             modules = commonModules ++ stableModules ++ [
               ./systems/hosts/demeter.nix
             ];
-            syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
+            # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
           };
         };