Nix 101 Course / Section 7: Advanced packaging topics
Premium

7.1 Source filtering with lib.fileset

Lesson 47 of 68 · 17:29

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

Fixing a typo in a README should never cost you hours of recompilation, yet with src = ./. that is exactly what happens. This lesson covers source filtering in Nix with lib.fileset, lib.cleanSource, and cleanSourceWith, so only the files that actually matter reach the build sandbox. The payoff: more cache hits, fewer rebuilds, and a smaller Nix store.

In this video

  • Six ways an unfiltered src = ./. hurts you, including one almost nobody expects: the name of your checkout folder
  • lib.cleanSource as the quick fix, and cleanSourceWith with a custom predicate that drops every .nix file
  • Allowlist filtering with lib.fileset.unions, and why it is the safest and most readable style
  • Composing filters like Lego bricks: filtering by file extension, difference, and gitTracked, each a one-liner from a real project
  • Tracing a filter that drops the wrong files, and the warning sign that your filtering has grown too complicated

After this lesson

You can point any derivation at exactly the files it needs, and you know the one restructuring trick that makes source filtering unnecessary in the first place.

Links: