summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/sources.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/sources.nix b/lib/sources.nix
index 407f9d21b8b..407829b547b 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -12,6 +12,7 @@ let
     tryEval
     ;
   inherit (lib)
+    boolToString
     filter
     getAttr
     isString
@@ -90,6 +91,29 @@ let
       name = if name != null then name else orig.name;
     };
 
+  /*
+    Add logging to a source, for troubleshooting the filtering behavior.
+    Type:
+      sources.trace :: sourceLike -> Source
+  */
+  trace =
+    # Source to debug. The returned source will behave like this source, but also log its filter invocations.
+    src:
+    let
+      attrs = toSourceAttributes src;
+    in
+      fromSourceAttributes (
+        attrs // {
+          filter = path: type:
+            let
+              r = attrs.filter path type;
+            in
+              builtins.trace "${attrs.name}.filter ${path} = ${boolToString r}" r;
+        }
+      ) // {
+        satisfiesSubpathInvariant = src ? satisfiesSubpathInvariant && src.satisfiesSubpathInvariant;
+      };
+
   # Filter sources by a list of regular expressions.
   #
   # E.g. `src = sourceByRegex ./my-subproject [".*\.py$" "^database.sql$"]`
@@ -233,5 +257,7 @@ in {
 
     sourceByRegex
     sourceFilesBySuffices
+
+    trace
     ;
 }