Noogλe
Function of the day
Takes 2 arguments
e1, e2
Warning
filterSourceshould not be used to filter store paths. SincefilterSourceuses the name of the input directory while naming the output directory, doing so produces a directory name in the form of<hash2>-<hash>-<name>, where<hash>-<name>is the name of the input directory. Since<hash>depends on the unfiltered directory, the name of the output directory indirectly depends on files that are filtered out by the function. This triggers a rebuild even when a filtered out file is changed. Usebuiltins.pathinstead, which allows specifying the name of the output directory.This function allows you to copy sources into the Nix store while filtering certain files. For instance, suppose that you want to use the directory
source-diras an input to a Nix expression, e.g.stdenv.mkDerivation { ... src = ./source-dir; }However, if
source-diris a Subversion working copy, then all of those annoying.svnsubdirectories are also copied to the store. Worse, the contents of those directories may change a lot, causing lots of spurious rebuilds. WithfilterSourceyou can filter out the.svndirectories:src = builtins.filterSource (path: type: type != "directory" || baseNameOf path != ".svn") ./source-dir;Thus, the first argument e1 must be a predicate function that is called for each regular file, directory or symlink in the source tree e2. If the function returns
true, the file is copied to the Nix store, otherwise it is omitted. The function is called with two arguments. The first is the full path of the file. The second is a string that identifies the type of the file, which is either"regular","directory","symlink"or"unknown"(for other kinds of files such as device nodes or fifos — but note that those cannot be copied to the Nix store, so if the predicate returnstruefor them, the copy fails). If you exclude a directory, the entire corresponding subtree of e2 is excluded.