summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-02-21 12:36:42 +0100
committerRobert Hensing <robert@roberthensing.nl>2021-05-29 16:03:55 +0200
commit4cf56e56405a226d8b21e8643e32a10b60930ae9 (patch)
tree92e5323c12a13a6436f3b179d9172115d916a17d /lib
parent4a025692d1daf90b3a9cefe2d996e163e1ad05d3 (diff)
downloadnixpkgs-4cf56e56405a226d8b21e8643e32a10b60930ae9.tar
nixpkgs-4cf56e56405a226d8b21e8643e32a10b60930ae9.tar.gz
nixpkgs-4cf56e56405a226d8b21e8643e32a10b60930ae9.tar.bz2
nixpkgs-4cf56e56405a226d8b21e8643e32a10b60930ae9.tar.lz
nixpkgs-4cf56e56405a226d8b21e8643e32a10b60930ae9.tar.xz
nixpkgs-4cf56e56405a226d8b21e8643e32a10b60930ae9.tar.zst
nixpkgs-4cf56e56405a226d8b21e8643e32a10b60930ae9.zip
lib.sources.trace: init
Diffstat (limited to 'lib')
-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
     ;
 }