Skip to content

Commit e12b54c

Browse files
committed
More composability, try out both absolute and subpath versions
1 parent 81dae56 commit e12b54c

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

lib/sources.nix

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,26 @@ let
270270
outPath = builtins.path { inherit filter name; path = origSrc; };
271271
};
272272

273-
predicateFilter = { name ? "source", src, predicate }:
273+
predicateFilterPath = { src, predicate }:
274274
let
275-
isFiltered = src ? _isLibCleanSourceWith;
276-
origSrc = if isFiltered then src.origSrc else src;
277-
removeBase = lib.path.subpath.removePrefix (lib.path.deconstructPath origSrc).subpath;
278-
in lib.cleanSourceWith {
279-
inherit name src;
280-
filter = absolutePath: type:
281-
assert lib.isString absolutePath;
282-
let subpath = removeBase (lib.substring 1 (-1) absolutePath);
283-
in predicate { inherit type subpath; };
275+
orig = toSourceAttributes src;
276+
removeBase = lib.path.subpath.removePrefix (lib.path.deconstructPath orig.origSrc).subpath;
277+
toPath = str: lib.path.append orig.origSrc (removeBase (lib.substring 1 (-1) str));
278+
in fromSourceAttributes {
279+
inherit (orig) name origSrc;
280+
filter = pathString: type: predicate { path = toPath pathString; inherit type; }
281+
&& orig.filter pathString type;
282+
};
283+
284+
predicateFilterSubpath = { src, predicate }:
285+
let
286+
orig = toSourceAttributes src;
287+
removeBase = lib.path.subpath.removePrefix (lib.path.deconstructPath orig.origSrc).subpath;
288+
toSubpath = str: removeBase (lib.substring 1 (-1) str);
289+
in fromSourceAttributes {
290+
inherit (orig) name origSrc;
291+
filter = pathString: type: predicate { subpath = toSubpath pathString; inherit type; }
292+
&& orig.filter pathString type;
284293
};
285294

286295
in {
@@ -302,6 +311,7 @@ in {
302311
sourceFilesBySuffices
303312

304313
trace
305-
predicateFilter
314+
predicateFilterPath
315+
predicateFilterSubpath
306316
;
307317
}

0 commit comments

Comments
 (0)