···
152
+
Incrementally evaluate and trace a file set in a pretty way.
153
+
This function is only intended for debugging purposes.
154
+
The exact tracing format is unspecified and may change.
156
+
This function takes a final argument to return.
157
+
In comparison, [`traceVal`](#function-library-lib.fileset.traceVal) returns
158
+
the given file set argument.
160
+
This variant is useful for tracing file sets in the Nix repl.
163
+
trace :: FileSet -> Any -> Any
166
+
trace (unions [ ./Makefile ./src ./tests/run.sh ]) null
168
+
trace: /home/user/src/myProject
169
+
trace: - Makefile (regular)
170
+
trace: - src (all files in directory)
172
+
trace: - run.sh (regular)
177
+
The file set to trace.
179
+
This argument can also be a path,
180
+
which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
184
+
# "fileset" would be a better name, but that would clash with the argument name,
185
+
# and we cannot change that because of https://github.com/nix-community/nixdoc/issues/76
186
+
actualFileset = _coerce "lib.fileset.trace: Argument" fileset;
189
+
(_printFileset actualFileset)
193
+
Incrementally evaluate and trace a file set in a pretty way.
194
+
This function is only intended for debugging purposes.
195
+
The exact tracing format is unspecified and may change.
197
+
This function returns the given file set.
198
+
In comparison, [`trace`](#function-library-lib.fileset.trace) takes another argument to return.
200
+
This variant is useful for tracing file sets passed as arguments to other functions.
203
+
traceVal :: FileSet -> FileSet
208
+
fileset = traceVal (unions [
215
+
trace: /home/user/src/myProject
216
+
trace: - Makefile (regular)
217
+
trace: - src (all files in directory)
219
+
trace: - run.sh (regular)
220
+
"/nix/store/...-source"
224
+
The file set to trace and return.
226
+
This argument can also be a path,
227
+
which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
231
+
# "fileset" would be a better name, but that would clash with the argument name,
232
+
# and we cannot change that because of https://github.com/nix-community/nixdoc/issues/76
233
+
actualFileset = _coerce "lib.fileset.traceVal: Argument" fileset;
236
+
(_printFileset actualFileset)
237
+
# We could also return the original fileset argument here,
238
+
# but that would then duplicate work for consumers of the fileset, because then they have to coerce it again
Add the local files contained in `fileset` to the store as a single [store path](https://nixos.org/manual/nix/stable/glossary#gloss-store-path) rooted at `root`.
The result is the store path as a string-like value, making it usable e.g. as the `src` of a derivation, or in string interpolation:
···
296
-
Create a file set with the same files as a `lib.sources`-based value.
297
-
This does not import any of the files into the store.
299
-
This can be used to gradually migrate from `lib.sources`-based filtering to `lib.fileset`.
301
-
A file set can be turned back into a source using [`toSource`](#function-library-lib.fileset.toSource).
304
-
File sets cannot represent empty directories.
305
-
Turning the result of this function back into a source using `toSource` will therefore not preserve empty directories.
309
-
fromSource :: SourceLike -> FileSet
312
-
# There's no cleanSource-like function for file sets yet,
313
-
# but we can just convert cleanSource to a file set and use it that way
316
-
fileset = fromSource (lib.sources.cleanSource ./.);
319
-
# Keeping a previous sourceByRegex (which could be migrated to `lib.fileset.unions`),
320
-
# but removing a subdirectory using file set functions
322
-
(fromSource (lib.sources.sourceByRegex ./. [
324
-
# This regex includes everything in ./doc
329
-
# Use cleanSource, but limit it to only include ./Makefile and files under ./src
331
-
(fromSource (lib.sources.cleanSource ./.))
337
-
fromSource = source:
339
-
# This function uses `._isLibCleanSourceWith`, `.origSrc` and `.filter`,
340
-
# which are technically internal to lib.sources,
341
-
# but we'll allow this since both libraries are in the same code base
342
-
# and this function is a bridge between them.
343
-
isFiltered = source ? _isLibCleanSourceWith;
344
-
path = if isFiltered then source.origSrc else source;
346
-
# We can only support sources created from paths
347
-
if ! isPath path then
348
-
if isStringLike path then
350
-
lib.fileset.fromSource: The source origin of the argument is a string-like value ("${toString path}"), but it should be a path instead.
351
-
Sources created from paths in strings cannot be turned into file sets, use `lib.sources` or derivations instead.''
354
-
lib.fileset.fromSource: The source origin of the argument is of type ${typeOf path}, but it should be a path instead.''
355
-
else if ! pathExists path then
357
-
lib.fileset.fromSource: The source origin (${toString path}) of the argument is a path that does not exist.''
358
-
else if isFiltered then
359
-
_fromSourceFilter path source.filter
361
-
# If there's no filter, no need to run the expensive conversion, all subpaths will be included
The file set containing all files that are in either of two given file sets.
This is the same as [`unions`](#function-library-lib.fileset.unions),
but takes just two file sets instead of a list.
···
457
-
Filter a file set to only contain files matching some predicate.
470
-
# Include all regular `default.nix` files in the current directory
471
-
fileFilter (file: file.name == "default.nix") ./.
473
-
# Include all non-Nix files from the current directory
474
-
fileFilter (file: ! hasSuffix ".nix" file.name) ./.
476
-
# Include all files that start with a "." in the current directory
477
-
fileFilter (file: hasPrefix "." file.name) ./.
479
-
# Include all regular files (not symlinks or others) in the current directory
480
-
fileFilter (file: file.type == "regular") ./.
484
-
The predicate function to call on all files contained in given file set.
485
-
A file is included in the resulting file set if this function returns true for it.
487
-
This function is called with an attribute set containing these attributes:
489
-
- `name` (String): The name of the file
491
-
- `type` (String, one of `"regular"`, `"symlink"` or `"unknown"`): The type of the file.
492
-
This matches result of calling [`builtins.readFileType`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-readFileType) on the file's path.
494
-
Other attributes may be added in the future.
497
-
# The path whose files to filter
499
-
if ! isFunction predicate then
501
-
lib.fileset.fileFilter: First argument is of type ${typeOf predicate}, but it should be a function instead.''
502
-
else if ! isPath path then
503
-
if path._type or "" == "fileset" then
505
-
lib.fileset.fileFilter: Second argument is a file set, but it should be a path instead.
506
-
If you need to filter files in a file set, use `intersection fileset (fileFilter pred ./.)` instead.''
509
-
lib.fileset.fileFilter: Second argument is of type ${typeOf path}, but it should be a path instead.''
510
-
else if ! pathExists path then
512
-
lib.fileset.fileFilter: Second argument (${toString path}) is a path that does not exist.''
514
-
_fileFilter predicate path;
The file set containing all files that are in both of two given file sets.
See also [Intersection (set theory)](https://en.wikipedia.org/wiki/Intersection_(set_theory)).
···
608
-
Incrementally evaluate and trace a file set in a pretty way.
609
-
This function is only intended for debugging purposes.
610
-
The exact tracing format is unspecified and may change.
569
+
Filter a file set to only contain files matching some predicate.
612
-
This function takes a final argument to return.
613
-
In comparison, [`traceVal`](#function-library-lib.fileset.traceVal) returns
614
-
the given file set argument.
582
+
# Include all regular `default.nix` files in the current directory
583
+
fileFilter (file: file.name == "default.nix") ./.
616
-
This variant is useful for tracing file sets in the Nix repl.
585
+
# Include all non-Nix files from the current directory
586
+
fileFilter (file: ! hasSuffix ".nix" file.name) ./.
619
-
trace :: FileSet -> Any -> Any
588
+
# Include all files that start with a "." in the current directory
589
+
fileFilter (file: hasPrefix "." file.name) ./.
622
-
trace (unions [ ./Makefile ./src ./tests/run.sh ]) null
624
-
trace: /home/user/src/myProject
625
-
trace: - Makefile (regular)
626
-
trace: - src (all files in directory)
628
-
trace: - run.sh (regular)
591
+
# Include all regular files (not symlinks or others) in the current directory
592
+
fileFilter (file: file.type == "regular") ./.
633
-
The file set to trace.
596
+
The predicate function to call on all files contained in given file set.
597
+
A file is included in the resulting file set if this function returns true for it.
635
-
This argument can also be a path,
636
-
which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
599
+
This function is called with an attribute set containing these attributes:
601
+
- `name` (String): The name of the file
603
+
- `type` (String, one of `"regular"`, `"symlink"` or `"unknown"`): The type of the file.
604
+
This matches result of calling [`builtins.readFileType`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-readFileType) on the file's path.
606
+
Other attributes may be added in the future.
640
-
# "fileset" would be a better name, but that would clash with the argument name,
641
-
# and we cannot change that because of https://github.com/nix-community/nixdoc/issues/76
642
-
actualFileset = _coerce "lib.fileset.trace: Argument" fileset;
645
-
(_printFileset actualFileset)
609
+
# The path whose files to filter
611
+
if ! isFunction predicate then
613
+
lib.fileset.fileFilter: First argument is of type ${typeOf predicate}, but it should be a function instead.''
614
+
else if ! isPath path then
615
+
if path._type or "" == "fileset" then
617
+
lib.fileset.fileFilter: Second argument is a file set, but it should be a path instead.
618
+
If you need to filter files in a file set, use `intersection fileset (fileFilter pred ./.)` instead.''
621
+
lib.fileset.fileFilter: Second argument is of type ${typeOf path}, but it should be a path instead.''
622
+
else if ! pathExists path then
624
+
lib.fileset.fileFilter: Second argument (${toString path}) is a path that does not exist.''
626
+
_fileFilter predicate path;
649
-
Incrementally evaluate and trace a file set in a pretty way.
650
-
This function is only intended for debugging purposes.
651
-
The exact tracing format is unspecified and may change.
629
+
Create a file set with the same files as a `lib.sources`-based value.
630
+
This does not import any of the files into the store.
653
-
This function returns the given file set.
654
-
In comparison, [`trace`](#function-library-lib.fileset.trace) takes another argument to return.
632
+
This can be used to gradually migrate from `lib.sources`-based filtering to `lib.fileset`.
656
-
This variant is useful for tracing file sets passed as arguments to other functions.
634
+
A file set can be turned back into a source using [`toSource`](#function-library-lib.fileset.toSource).
659
-
traceVal :: FileSet -> FileSet
637
+
File sets cannot represent empty directories.
638
+
Turning the result of this function back into a source using `toSource` will therefore not preserve empty directories.
664
-
fileset = traceVal (unions [
671
-
trace: /home/user/src/myProject
672
-
trace: - Makefile (regular)
673
-
trace: - src (all files in directory)
675
-
trace: - run.sh (regular)
676
-
"/nix/store/...-source"
680
-
The file set to trace and return.
642
+
fromSource :: SourceLike -> FileSet
645
+
# There's no cleanSource-like function for file sets yet,
646
+
# but we can just convert cleanSource to a file set and use it that way
649
+
fileset = fromSource (lib.sources.cleanSource ./.);
682
-
This argument can also be a path,
683
-
which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
652
+
# Keeping a previous sourceByRegex (which could be migrated to `lib.fileset.unions`),
653
+
# but removing a subdirectory using file set functions
655
+
(fromSource (lib.sources.sourceByRegex ./. [
657
+
# This regex includes everything in ./doc
662
+
# Use cleanSource, but limit it to only include ./Makefile and files under ./src
664
+
(fromSource (lib.sources.cleanSource ./.))
670
+
fromSource = source:
687
-
# "fileset" would be a better name, but that would clash with the argument name,
688
-
# and we cannot change that because of https://github.com/nix-community/nixdoc/issues/76
689
-
actualFileset = _coerce "lib.fileset.traceVal: Argument" fileset;
672
+
# This function uses `._isLibCleanSourceWith`, `.origSrc` and `.filter`,
673
+
# which are technically internal to lib.sources,
674
+
# but we'll allow this since both libraries are in the same code base
675
+
# and this function is a bridge between them.
676
+
isFiltered = source ? _isLibCleanSourceWith;
677
+
path = if isFiltered then source.origSrc else source;
692
-
(_printFileset actualFileset)
693
-
# We could also return the original fileset argument here,
694
-
# but that would then duplicate work for consumers of the fileset, because then they have to coerce it again
679
+
# We can only support sources created from paths
680
+
if ! isPath path then
681
+
if isStringLike path then
683
+
lib.fileset.fromSource: The source origin of the argument is a string-like value ("${toString path}"), but it should be a path instead.
684
+
Sources created from paths in strings cannot be turned into file sets, use `lib.sources` or derivations instead.''
687
+
lib.fileset.fromSource: The source origin of the argument is of type ${typeOf path}, but it should be a path instead.''
688
+
else if ! pathExists path then
690
+
lib.fileset.fromSource: The source origin (${toString path}) of the argument is a path that does not exist.''
691
+
else if isFiltered then
692
+
_fromSourceFilter path source.filter
694
+
# If there's no filter, no need to run the expensive conversion, all subpaths will be included
Create a file set containing all [Git-tracked files](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository) in a repository.