summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorTom Hunger <tehunger@gmail.com>2017-02-17 18:56:39 +0000
committerTom Hunger <tehunger@gmail.com>2017-02-17 18:56:39 +0000
commitcb96ed615e48d13c165046363623f0f0e7007796 (patch)
tree1fa38a81df2a6108f3f007b2fc581cc1d94757ab /lib
parent624cd8ae9eecc42d04559b8f1c36cb1bd4796fbf (diff)
downloadnixpkgs-cb96ed615e48d13c165046363623f0f0e7007796.tar
nixpkgs-cb96ed615e48d13c165046363623f0f0e7007796.tar.gz
nixpkgs-cb96ed615e48d13c165046363623f0f0e7007796.tar.bz2
nixpkgs-cb96ed615e48d13c165046363623f0f0e7007796.tar.lz
nixpkgs-cb96ed615e48d13c165046363623f0f0e7007796.tar.xz
nixpkgs-cb96ed615e48d13c165046363623f0f0e7007796.tar.zst
nixpkgs-cb96ed615e48d13c165046363623f0f0e7007796.zip
lib: Add a function to filter sources by regular expressions.
Diffstat (limited to 'lib')
-rw-r--r--lib/sources.nix6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/sources.nix b/lib/sources.nix
index f41abe1e1ea..8f312a9db5c 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -26,6 +26,12 @@ rec {
 
   cleanSource = builtins.filterSource cleanSourceFilter;
 
+  # Filter sources by a list of regular expressions.
+  #
+  # E.g. `src = sourceByRegex ./my-subproject [".*\.py$" "^database.sql$"]`
+  sourceByRegex = src: regexes: builtins.filterSource (path: type:
+    let relPath = lib.removePrefix (toString src + "/") (toString path);
+    in lib.any (re: builtins.match re relPath != null) regexes) src;
 
   # Get all files ending with the specified suffices from the given
   # directory or its descendants.  E.g. `sourceFilesBySuffices ./dir