Excluding a subdirectory when using local paths

Is it possible to do something like src = ./.; while excluding a certain directory? (node_modules, specifically)
I know I could do something like srcs = [ ./package.json ./lib ... ]; but then I’d have to remember to add it to the derivation if I want to add a new folder in the future.
I also don’t quite understand what’s going on with local paths overall. Where’s the best source of information about them?

1 Like

something like this should work, see builtins.filterSource in the manual.

src = builtins.filterSource
    (path: type: !(type == "directory" && baseNameOf path == "node_modules"))
    ./source-dir;
5 Likes

Perfect! Thank you :slight_smile:

Another option which lists files directly:

src = builtins.path {
  name = pname;
  path = ./.;
  filter = path: type:
    builtins.elem (/. + path) [
      ./content
      ./content/index.html
      ./package.json
      ./yarn.lock
    ];
};