Commit f2419310d47e

Vincent Demeester <vincent@sbr.pm>
2025-05-06 23:24:14
globals: add syncthing configuration…
… and remove that weird syncthingFolder field Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent b020d93
Changed files (6)
home/default.nix
@@ -2,12 +2,12 @@
   config,
   desktop,
   hostname,
-  syncthingFolders,
   lib,
   outputs,
   stateVersion,
   username,
   inputs,
+  globals,
   ...
 }:
 {
@@ -20,7 +20,9 @@
     ++ lib.optional (builtins.pathExists (
       ../systems/. + "/${hostname}/home.nix"
     )) ../systems/${hostname}/home.nix
-    ++ lib.optional ((builtins.length syncthingFolders) > 0) ./common/services/syncthing.nix;
+    ++ lib.optional (globals.fn.hasSyncthingFolders
+      globals.machines."${hostname}"
+    ) ./common/services/syncthing.nix;
 
   home = {
     inherit username stateVersion;
lib/default.nix
@@ -14,6 +14,9 @@
       desktop ? null,
       system ? "x86_64-linux",
     }:
+    let
+      globals = import ../globals.nix { inherit (inputs.nixpkgs) lib; };
+    in
     inputs.home-manager.lib.homeManagerConfiguration {
       pkgs = inputs.nixpkgs.legacyPackages.${system};
       extraSpecialArgs = {
@@ -24,6 +27,7 @@
           stateVersion
           hostname
           desktop
+          globals
           ;
         username = user;
       };
@@ -37,13 +41,12 @@
     {
       hostname,
       desktop ? null,
-      syncthingFolders ? [ ],
       system ? "x86_64-linux",
       pkgsInput ? inputs.nixpkgs,
       homeInput ? inputs.home-manager,
     }:
     let
-      globals = import ../globals.nix;
+      globals = import ../globals.nix { inherit (pkgsInput) lib; };
       specialArgs = {
         inherit
           self
@@ -52,7 +55,6 @@
           stateVersion
           hostname
           desktop
-          syncthingFolders
           system
           globals
           ;
systems/common/users/vincent.nix
@@ -3,11 +3,11 @@
   lib,
   config,
   desktop,
-  syncthingFolders,
   hostname,
   outputs,
   stateVersion,
   inputs,
+  globals,
   ...
 }:
 let
@@ -89,8 +89,8 @@ in
       pkgs
       lib
       hostname
-      syncthingFolders
       desktop
+      globals
       outputs
       inputs
       stateVersion
systems/kyushu/extra.nix
@@ -1,4 +1,9 @@
-{ pkgs, lib, globals, ... }:
+{
+  pkgs,
+  lib,
+  globals,
+  ...
+}:
 {
 
   imports = [
flake.nix
@@ -80,13 +80,6 @@
         kyushu = libx.mkHost {
           hostname = "kyushu";
           desktop = "sway";
-          syncthingFolders = [
-            "org"
-            "documents"
-            "sync"
-            "screenshots"
-            "wallpapers"
-          ];
         };
         # Work workstation (unstable)
         # FIXME migrate to libx.mkHost
@@ -100,7 +93,6 @@
               inputs.nixos-hardware.nixosModules.common-pc-laptop-ssd
               ./systems/hosts/aomi.nix
             ];
-          # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
         };
         # Work server (stable ?)
         # kobe = libx.mkHost {
@@ -118,7 +110,6 @@
             ++ [
               ./systems/hosts/shikoku.nix
             ];
-          # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
         };
         sakhalin = inputs.nixpkgs-24_11.lib.nixosSystem {
           system = "x86_64-linux";
@@ -129,7 +120,6 @@
               inputs.nixos-hardware.nixosModules.common-pc-ssd
               ./systems/hosts/sakhalin.nix
             ];
-          # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
         };
         kerkouane = inputs.nixpkgs-24_11.lib.nixosSystem {
           system = "x86_64-linux";
@@ -140,7 +130,6 @@
               ./systems/modules/services/govanityurl.nix
               ./systems/hosts/kerkouane.nix
             ];
-          # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
         };
         # carthage = inputs.nixpkgs-24_11.lib.nixosSystem {
         #   system = "aarch64-linux";
@@ -158,7 +147,6 @@
             ++ [
               ./systems/hosts/athena.nix
             ];
-          # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
         };
         # demeter
         demeter = inputs.nixpkgs-24_11.lib.nixosSystem {
@@ -169,7 +157,6 @@
             ++ [
               ./systems/hosts/demeter.nix
             ];
-          # syncthingFolders = [ "org" "documents" "sync" "screenshots" "wallpapers" ];
         };
       };
 
globals.nix
@@ -1,3 +1,4 @@
+{ lib, ... }:
 {
   net = {
     vpn = {
@@ -17,9 +18,28 @@
           ips = [ "10.100.0.19" ];
         };
       };
+      syncthing = {
+        folders = {
+          org = { };
+          documents = { };
+          sync = { };
+          screenshots = { };
+          wallpapers = { };
+          photos = {
+            type = "receiveonly";
+            paused = true; # TODO: implement this, start as paused
+          };
+          music = {
+            type = "receiveonly";
+            paused = true; # TODO: implement this, start as paused
+          };
+        };
+      };
     };
   };
+  # FIXME Maybe I should move this elsewhere, in ./lib maybe ?
   fn = {
     wg-ips = ips: builtins.map (x: "${x}/24") ips;
+    hasSyncthingFolders = host: (builtins.length (lib.attrsets.attrValues host.syncthing.folders)) > 0;
   };
 }