about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-01-16 15:34:51 +0100
committerSoispha <soispha@vhack.eu>2024-01-16 16:23:11 +0100
commite341aeaf29e7631117f5b90c10a787b66339134a (patch)
tree8888c5c7ce09640b0dd8c625ee4b9ce046da4a11
parentfix(hm/conf/unison): Ignore links and the task dir (diff)
downloadnixos-config-e341aeaf29e7631117f5b90c10a787b66339134a.tar.gz
nixos-config-e341aeaf29e7631117f5b90c10a787b66339134a.zip
fix(hm/conf/unison): Correctly implement path ignoring
Diffstat (limited to '')
-rw-r--r--hm/soispha/conf/unison/default.nix47
1 files changed, 42 insertions, 5 deletions
diff --git a/hm/soispha/conf/unison/default.nix b/hm/soispha/conf/unison/default.nix
index f3c05c3e..831993c1 100644
--- a/hm/soispha/conf/unison/default.nix
+++ b/hm/soispha/conf/unison/default.nix
@@ -15,8 +15,6 @@
     auto = "true";
     # This is useless, with hm links
     links = "false";
-    # already synchronized by the taskserver
-    ignore = "/home/soispha/.local/share/task";
   };
 
   paths_to_keep = [
@@ -32,6 +30,13 @@
     "~/school"
     "~/repos"
   ];
+  paths_to_ignore = [
+    # already synchronized by the taskserver
+    "~/.local/share/task"
+
+    # Should not be synchronized
+    "~/.local/share/unison"
+  ];
 
   hostName = let
     hn = nixosConfig.networking.hostName;
@@ -65,10 +70,41 @@
     };
   };
 
+  getIgnoredSingle = path: path_to_ignore: let
+    clean_path_to_ignore = mkPath path_to_ignore;
+    commonPath = builtins.substring 0 (builtins.stringLength path) clean_path_to_ignore;
+  in
+    if commonPath == path
+    then let
+      preFinalPath =
+        builtins.substring (builtins.stringLength commonPath)
+        (builtins.stringLength clean_path_to_ignore)
+        clean_path_to_ignore;
+      finalPath =
+        if lib.strings.hasPrefix "/" preFinalPath
+        then lib.strings.removePrefix "/" preFinalPath
+        else preFinalPath;
+    in "BelowPath ${finalPath}"
+    else null;
+
+  getIgnored = paths_to_ignore: path:
+    serialiseArgs {
+      ignore =
+        builtins.filter (x: x != null) (builtins.map (getIgnoredSingle path) paths_to_ignore);
+    };
+
   serialiseArg = key: val:
-    lib.strings.concatStringsSep " "
-    (lib.forEach (lib.toList val) (x: lib.strings.escapeShellArg "-${key}=${lib.escape ["="] x}"));
-  serialiseArgs = args: lib.strings.concatStringsSep " " (lib.mapAttrsToList serialiseArg args);
+    if builtins.typeOf val == "string"
+    then lib.strings.escapeShellArg "-${key}=${lib.strings.escape ["="] val}"
+    else if builtins.typeOf val == "list"
+    then lib.strings.concatStringsSep " " (builtins.map (serialiseArg key) val)
+    else builtins.throw "Unsupported type: ${builtins.typeOf val}";
+  serialiseArgs = args:
+    lib.strings.concatStringsSep " " (
+      lib.attrsets.mapAttrsToList
+      serialiseArg
+      args
+    );
 
   esa = a: lib.strings.escapeShellArg a;
 
@@ -79,6 +115,7 @@
     lib.strings.concatStringsSep " " [
       "unison"
       "${serialiseArgs unisonOptions}"
+      "${getIgnored paths_to_ignore path}"
       "${esa path}"
       (esa "ssh://${config.home.username}@${hostName}.fritz.box/${path}")
     ];