# Filtering Source Trees with Nix and Nixpkgs

**URL:** https://discourse.nixos.org/t/filtering-source-trees-with-nix-and-nixpkgs/19148
**Category:** Guides
**Created:** [May 14, 2022, 7:02pm UTC](https://discourse.nixos.org/t/filtering-source-trees-with-nix-and-nixpkgs/19148 "2022-05-14T19:02:16Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![Ten](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@Ten](https://discourse.nixos.org/u/Ten)
#### Post date: [May 1, 2024, 7:56pm UTC](https://discourse.nixos.org/t/filtering-source-trees-with-nix-and-nixpkgs/19148/4 "2024-05-01T19:56:14Z")

</div>

Thanks! I was just looking at it but I still couldn’t find a way in there to do the regular directory traversal that filterSource does, but only creating a directory once we’re about to put an actual (not filtered-out) file inside, in order to not update hashes and cause recompilations based on unrelated directories.  
It does look like something that I’m very likely not the first to need and should consequently already exist in Nix…  
Is there such a thing?

EDIT: Ah [this post](https://discourse.nixos.org/t/easy-source-filtering-with-file-sets/29117) seems to suggest that maybe lib.fileset by default does filter empty directories? Does this mean then that [#8820](https://github.com/NixOS/nix/issues/8820) (that you opened!) is out of date?

---

_[View the full topic](https://discourse.nixos.org/t/filtering-source-trees-with-nix-and-nixpkgs/19148)._
