···11-<!-- TODO: Render this document in front of function documentation in case https://github.com/nix-community/nixdoc/issues/19 is ever supported -->
22-33-# File sets {#sec-fileset}
44-55-The [`lib.fileset`](#sec-functions-library-fileset) library allows you to work with _file sets_.
66-A file set is a mathematical set of local files that can be added to the Nix store for use in Nix derivations.
77-File sets are easy and safe to use, providing obvious and composable semantics with good error messages to prevent mistakes.
88-99-See the [function reference](#sec-functions-library-fileset) for function-specific documentation.
1010-1111-## Implicit coercion from paths to file sets {#sec-fileset-path-coercion}
1212-1313-All functions accepting file sets as arguments can also accept [paths](https://nixos.org/manual/nix/stable/language/values.html#type-path) as arguments.
1414-Such path arguments are implicitly coerced to file sets containing all files under that path:
1515-- A path to a file turns into a file set containing that single file.
1616-- A path to a directory turns into a file set containing all files _recursively_ in that directory.
1717-1818-If the path points to a non-existent location, an error is thrown.
1919-2020-::: {.note}
2121-Just like in Git, file sets cannot represent empty directories.
2222-Because of this, a path to a directory that contains no files (recursively) will turn into a file set containing no files.
2323-:::
2424-2525-:::{.note}
2626-File set coercion does _not_ add any of the files under the coerced paths to the store.
2727-Only the [`toSource`](#function-library-lib.fileset.toSource) function adds files to the Nix store, and only those files contained in the `fileset` argument.
2828-This is in contrast to using [paths in string interpolation](https://nixos.org/manual/nix/stable/language/values.html#type-path), which does add the entire referenced path to the store.
2929-:::
3030-3131-### Example {#sec-fileset-path-coercion-example}
3232-3333-Assume we are in a local directory with a file hierarchy like this:
3434-```
3535-├─ a/
3636-│ ├─ x (file)
3737-│ └─ b/
3838-│ └─ y (file)
3939-└─ c/
4040- └─ d/
4141-```
4242-4343-Here's a listing of which files get included when different path expressions get coerced to file sets:
4444-- `./.` as a file set contains both `a/x` and `a/b/y` (`c/` does not contain any files and is therefore omitted).
4545-- `./a` as a file set contains both `a/x` and `a/b/y`.
4646-- `./a/x` as a file set contains only `a/x`.
4747-- `./a/b` as a file set contains only `a/b/y`.
4848-- `./c` as a file set is empty, since neither `c` nor `c/d` contain any files.
+49
lib/fileset/default.nix
···11+/*
22+ <!-- This anchor is here for backwards compatibity -->
33+ []{#sec-fileset}
44+55+ The [`lib.fileset`](#sec-functions-library-fileset) library allows you to work with _file sets_.
66+ A file set is a mathematical set of local files that can be added to the Nix store for use in Nix derivations.
77+ File sets are easy and safe to use, providing obvious and composable semantics with good error messages to prevent mistakes.
88+99+ See the [function reference](#sec-functions-library-fileset) for function-specific documentation.
1010+1111+ ## Implicit coercion from paths to file sets {#sec-fileset-path-coercion}
1212+1313+ All functions accepting file sets as arguments can also accept [paths](https://nixos.org/manual/nix/stable/language/values.html#type-path) as arguments.
1414+ Such path arguments are implicitly coerced to file sets containing all files under that path:
1515+ - A path to a file turns into a file set containing that single file.
1616+ - A path to a directory turns into a file set containing all files _recursively_ in that directory.
1717+1818+ If the path points to a non-existent location, an error is thrown.
1919+2020+ ::: {.note}
2121+ Just like in Git, file sets cannot represent empty directories.
2222+ Because of this, a path to a directory that contains no files (recursively) will turn into a file set containing no files.
2323+ :::
2424+2525+ :::{.note}
2626+ File set coercion does _not_ add any of the files under the coerced paths to the store.
2727+ Only the [`toSource`](#function-library-lib.fileset.toSource) function adds files to the Nix store, and only those files contained in the `fileset` argument.
2828+ This is in contrast to using [paths in string interpolation](https://nixos.org/manual/nix/stable/language/values.html#type-path), which does add the entire referenced path to the store.
2929+ :::
3030+3131+ ### Example {#sec-fileset-path-coercion-example}
3232+3333+ Assume we are in a local directory with a file hierarchy like this:
3434+ ```
3535+ ├─ a/
3636+ │ ├─ x (file)
3737+ │ └─ b/
3838+ │ └─ y (file)
3939+ └─ c/
4040+ └─ d/
4141+ ```
4242+4343+ Here's a listing of which files get included when different path expressions get coerced to file sets:
4444+ - `./.` as a file set contains both `a/x` and `a/b/y` (`c/` does not contain any files and is therefore omitted).
4545+ - `./a` as a file set contains both `a/x` and `a/b/y`.
4646+ - `./a/x` as a file set contains only `a/x`.
4747+ - `./a/b` as a file set contains only `a/b/y`.
4848+ - `./c` as a file set is empty, since neither `c` nor `c/d` contain any files.
4949+*/
150{ lib }:
251let
352