Skip to content

lib.sources: source filtering functions

Functions for copying sources to the Nix store.

lib.sources.commitIdFromGitRepo

Get the commit id of a git repo.

path

: Function argument

Example

lib.sources.commitIdFromGitRepo usage example

commitIdFromGitRepo <nixpkgs/.git>

Located at lib/sources.nix:273 in <nixpkgs>.

lib.sources.cleanSource

Filters a source tree removing version control files and directories using cleanSourceFilter.

src

: Function argument

Example

lib.sources.cleanSource usage example

cleanSource ./.

Located at lib/sources.nix:275 in <nixpkgs>.

lib.sources.cleanSourceWith

Like builtins.filterSource, except it will compose with itself, allowing you to chain multiple calls together without any intermediate copies being put in the nix store.

structured function argument

: src

: A path or cleanSourceWith result to filter and/or rename.

filter

: Optional with default value: constant true (include everything) The function will be combined with the && operator such that src.filter is called lazily. For implementing a filter, see https://nixos.org/nix/manual/#builtin-filterSource Type: A function (path -> type -> bool)

name

: Optional name to use as part of the store path. This defaults to src.name or otherwise "source".

Example

lib.sources.cleanSourceWith usage example

lib.cleanSourceWith {
  filter = f;
  src = lib.cleanSourceWith {
    filter = g;
    src = ./.;
  };
}
# Succeeds!

builtins.filterSource f (builtins.filterSource g ./.)
# Fails!

Located at lib/sources.nix:276 in <nixpkgs>.

lib.sources.cleanSourceFilter

A basic filter for cleanSourceWith that removes directories of version control system, backup files (*~) and some generated files.

name

: Function argument

type

: Function argument

Located at lib/sources.nix:277 in <nixpkgs>.

lib.sources.sourceByRegex

Filter sources by a list of regular expressions.

src

: Function argument

regexes

: Function argument

Example

lib.sources.sourceByRegex usage example

src = sourceByRegex ./my-subproject [".*\.py$" "^database.sql$"]

Located at lib/sources.nix:281 in <nixpkgs>.

lib.sources.sourceFilesBySuffices

Type: sourceLike -> [String] -> Source

Get all files ending with the specified suffices from the given source directory or its descendants, omitting files that do not match any suffix. The result of the example below will include files like ./dir/module.c and ./dir/subdir/doc.xml if present.

src

: Path or source containing the files to be returned

exts

: A list of file suffix strings

Example

lib.sources.sourceFilesBySuffices usage example

sourceFilesBySuffices ./. [ ".xml" ".c" ]

Located at lib/sources.nix:282 in <nixpkgs>.

lib.sources.trace

Type: sources.trace :: sourceLike -> Source

Add logging to a source, for troubleshooting the filtering behavior.

src

: Source to debug. The returned source will behave like this source, but also log its filter invocations.

Located at lib/sources.nix:284 in <nixpkgs>.