Commit 26bc2325b679

Vincent Demeester <vincent@sbr.pm>
2021-09-28 19:25:02
systems: do not fail on syncthing for older nixos
the services (and folders) fields are not available before 21.11 (unstable at the time of this commit), so it would fail the build for stable builds (like k8s nodes, …) Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 075f7df
Changed files (1)
systems
modules
systems/modules/profiles/syncthing.nix
@@ -2,6 +2,7 @@
 
 with lib;
 let
+  unstable = versionOlder config.system.nixos.release "21.05";
   cfg = config.profiles.syncthing;
   isCurrentHost = n: v: n != config.networking.hostName;
   devices = {
@@ -32,39 +33,47 @@ in
     };
   };
   config = mkIf cfg.enable {
-    services.syncthing = {
-      enable = true;
-      user = "vincent";
-      dataDir = "/home/vincent/.syncthing";
-      configDir = "/home/vincent/.syncthing";
-      devices = filterAttrs isCurrentHost devices;
-      folders = {
-        "/home/vincent/sync" = {
-          label = "sync";
-          id = "7dshg-r8zr6";
-          devices = deviceNames;
-        };
-        "/home/vincent/desktop/org" = {
-          label = "org";
-          id = "sjpsr-xfwdu";
-          devices = deviceNames;
-        };
-        "/home/vincent/desktop/documents" = {
-          label = "documents";
-          id = "oftdb-t5anv";
-          devices = deviceNames;
-        };
-        "/home/vincent/desktop/pictures/screenshots" = {
-          label = "screenshots";
-          id = "prpsz-azlz9";
-          devices = deviceNames;
-        };
-        "/home/vincent/desktop/pictures/wallpapers" = {
-          label = "wallpapers";
-          id = "wpiah-ydwwx";
-          devices = deviceNames;
+    services.syncthing =
+      if (builtins.hasAttr "devices" config.services.syncthing)
+      then {
+        enable = true;
+        user = "vincent";
+        dataDir = "/home/vincent/.syncthing";
+        configDir = "/home/vincent/.syncthing";
+        devices = filterAttrs isCurrentHost devices;
+        folders = {
+          "/home/vincent/sync" = {
+            label = "sync";
+            id = "7dshg-r8zr6";
+            devices = deviceNames;
+          };
+          "/home/vincent/desktop/org" = {
+            label = "org";
+            id = "sjpsr-xfwdu";
+            devices = deviceNames;
+          };
+          "/home/vincent/desktop/documents" = {
+            label = "documents";
+            id = "oftdb-t5anv";
+            devices = deviceNames;
+          };
+          "/home/vincent/desktop/pictures/screenshots" = {
+            label = "screenshots";
+            id = "prpsz-azlz9";
+            devices = deviceNames;
+          };
+          "/home/vincent/desktop/pictures/wallpapers" = {
+            label = "wallpapers";
+            id = "wpiah-ydwwx";
+            devices = deviceNames;
+          };
         };
+      }
+      else {
+        enable = true;
+        user = "vincent";
+        dataDir = "/home/vincent/.syncthing";
+        configDir = "/home/vincent/.syncthing";
       };
-    };
   };
 }