Noogλe :: 2024

search input

Function of the day

  • Create a file set with the same files as a lib.sources-based value. This does not import any of the files into the store.

    This can be used to gradually migrate from lib.sources-based filtering to lib.fileset.

    A file set can be turned back into a source using toSource.

    File sets cannot represent empty directories. Turning the result of this function back into a source using toSource will therefore not preserve empty directories.

    Inputs

    source

    1. Function argument

    Type

    fromSource :: SourceLike -> FileSet
    

    Examples

    fromSource usage example

    # There's no cleanSource-like function for file sets yet,
    # but we can just convert cleanSource to a file set and use it that way
    toSource {
      root = ./.;
      fileset = fromSource (lib.sources.cleanSource ./.);
    }
    
    # Keeping a previous sourceByRegex (which could be migrated to `lib.fileset.unions`),
    # but removing a subdirectory using file set functions
    difference
      (fromSource (lib.sources.sourceByRegex ./. [
        "^README\.md$"
        # This regex includes everything in ./doc
        "^doc(/.*)?$"
      ])
      ./doc/generated
    
    # Use cleanSource, but limit it to only include ./Makefile and files under ./src
    intersection
      (fromSource (lib.sources.cleanSource ./.))
      (unions [
        ./Makefile
        ./src
      ]);