ctucx.git: nixfiles

ctucx' nixfiles

commit 21113590bbb7b290131a09b3b6acc803a1cbeba2
parent 45e5d3efd96302e2c1e95d8736ac58b7d75b7a16
Author: Leah (ctucx) <leah@ctu.cx>
Date: Fri, 21 Jan 2022 01:39:58 +0100

programs/syncthing: enable shares based on hostname, add shares
1 file changed, 57 insertions(+), 9 deletions(-)
M
configurations/programs/syncthing.nix
|
66
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
diff --git a/configurations/programs/syncthing.nix b/configurations/programs/syncthing.nix
@@ -9,9 +9,35 @@ let
     #todo: find something to manage secrets
   };
 
-  isCurrentHost  = n: v: n != config.networking.hostName;
-  deviceNames    = builtins.attrNames (lib.filterAttrs isCurrentHost devices);
-  isaDeviceNames = builtins.attrNames isaDevices;
+  enabledShares = {
+    desastro = [
+      "ctucx-audiobooks-orig"
+      "ctucx-music-orig"
+      "ctucx-media"
+      "ctucx-windoofs"
+    ];
+    lollo = [
+      "ctucx-audiobooks-orig"
+      "ctucx-music-orig"
+      "ctucx-media"
+      "ctucx-windoofs"
+    ];
+    stasicontainer = [
+      "ctucx-audiobooks-orig"
+      "ctucx-music-orig"
+    ];
+  };
+
+  deviceNames       = builtins.attrNames (lib.filterAttrs isCurrentHost devices);
+  isaDeviceNames    = builtins.attrNames isaDevices;
+
+  filterCurrentHost = devices: lib.remove config.networking.hostName devices;
+  isCurrentHost     = n: v: n != config.networking.hostName;
+  isShareEnabled    = share:
+    if builtins.hasAttr config.networking.hostName enabledShares then
+      (if builtins.elem share enabledShares.${config.networking.hostName} then true else false)
+    else
+      false;
 
   dataDir        = "/home/leah" + (if config.networking.hostName == "desastro" then "/syncthing" else "");
 

@@ -30,11 +56,11 @@ in {
 
       folders = {
 
-        "${dataDir}/Audiobooks (Originals)" = {
-          enable            = (if config.networking.hostName == "stasicontainer" then true else false);
+        "${dataDir}/Audiobooks (Originals)" = rec {
+          enable            = isShareEnabled "${id}";
           id                = "ctucx-audiobooks-orig";
           label             = "Audiobooks (Originals}";
-          devices           = [ "desastro" "lollo" ];
+          devices           = filterCurrentHost [ "desastro" "lollo" "stasicontainer" ];
           versioning.type   = "trashcan";
           versioning.params = {
             cleanoutDays = "10";

@@ -71,11 +97,11 @@ in {
           };
         };
 
-        "${dataDir}/Music (Originals)" = {
-          enable            = (if config.networking.hostName == "stasicontainer" then true else false);
+        "${dataDir}/Music (Originals)" = rec {
+          enable            = isShareEnabled "${id}";
           id                = "ctucx-music-orig";
           label             = "Music (Originals)";
-          devices           = [ "desastro" "lollo" ];
+          devices           = filterCurrentHost [ "desastro" "lollo" "stasicontainer" ];
           versioning.type   = "trashcan";
           versioning.params = {
             cleanoutDays = "10";

@@ -102,6 +128,28 @@ in {
           };
         };
 
+        "${dataDir}/Media (legacy)" = rec {
+          enable            = isShareEnabled "${id}";
+          id                = "ctucx-media";
+          label             = "Media (legacy)";
+          devices           = filterCurrentHost [ "desastro" "lollo" ];
+          versioning.type   = "trashcan";
+          versioning.params = {
+            cleanoutDays = "15";
+          };
+        };
+
+        "${dataDir}/Windows-Stuff" = rec {
+          enable            = isShareEnabled "${id}";
+          id                = "ctucx-windoofs";
+          label             = "Windows-Stuff";
+          devices           = filterCurrentHost [ "desastro" "lollo" ];
+          versioning.type   = "trashcan";
+          versioning.params = {
+            cleanoutDays = "10";
+          };
+        };
+