···11-/*
11+/**
22 <!-- This anchor is here for backwards compatibility -->
33 []{#sec-fileset}
44···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.
8899- ## Overview {#sec-fileset-overview}
99+ # Overview {#sec-fileset-overview}
10101111 Basics:
1212 - [Implicit coercion from paths to file sets](#sec-fileset-path-coercion)
···5858 see [this issue](https://github.com/NixOS/nixpkgs/issues/266356) to request it.
595960606161- ## Implicit coercion from paths to file sets {#sec-fileset-path-coercion}
6161+ # Implicit coercion from paths to file sets {#sec-fileset-path-coercion}
62626363 All functions accepting file sets as arguments can also accept [paths](https://nixos.org/manual/nix/stable/language/values.html#type-path) as arguments.
6464 Such path arguments are implicitly coerced to file sets containing all files under that path:
···7878 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.
7979 :::
80808181- ### Example {#sec-fileset-path-coercion-example}
8181+ ## Example {#sec-fileset-path-coercion-example}
82828383 Assume we are in a local directory with a file hierarchy like this:
8484 ```
···157157158158in {
159159160160- /*
160160+ /**
161161 Create a file set from a path that may or may not exist:
162162 - If the path does exist, the path is [coerced to a file set](#sec-fileset-path-coercion).
163163 - If the path does not exist, a file set containing no files is returned.
164164165165- Type:
166166- maybeMissing :: Path -> FileSet
165165+166166+ # Inputs
167167+168168+ `path`
169169+170170+ : 1\. Function argument
171171+172172+ # Type
167173168168- Example:
169169- # All files in the current directory, but excluding main.o if it exists
170170- difference ./. (maybeMissing ./main.o)
174174+ ```
175175+ maybeMissing :: Path -> FileSet
176176+ ```
177177+178178+ # Examples
179179+ :::{.example}
180180+ ## `lib.fileset.maybeMissing` usage example
181181+182182+ ```nix
183183+ # All files in the current directory, but excluding main.o if it exists
184184+ difference ./. (maybeMissing ./main.o)
185185+ ```
186186+187187+ :::
171188 */
172189 maybeMissing =
173190 path:
···183200 else
184201 _singleton path;
185202186186- /*
203203+ /**
187204 Incrementally evaluate and trace a file set in a pretty way.
188205 This function is only intended for debugging purposes.
189206 The exact tracing format is unspecified and may change.
···194211195212 This variant is useful for tracing file sets in the Nix repl.
196213197197- Type:
198198- trace :: FileSet -> Any -> Any
199214200200- Example:
201201- trace (unions [ ./Makefile ./src ./tests/run.sh ]) null
202202- =>
203203- trace: /home/user/src/myProject
204204- trace: - Makefile (regular)
205205- trace: - src (all files in directory)
206206- trace: - tests
207207- trace: - run.sh (regular)
208208- null
209209- */
210210- trace =
211211- /*
212212- The file set to trace.
215215+ # Inputs
216216+217217+ `fileset`
218218+219219+ : The file set to trace.
220220+221221+ This argument can also be a path,
222222+ which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
223223+224224+ `val`
225225+226226+ : The value to return.
213227214214- This argument can also be a path,
215215- which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
216216- */
217217- fileset:
228228+ # Type
229229+230230+ ```
231231+ trace :: FileSet -> Any -> Any
232232+ ```
233233+234234+ # Examples
235235+ :::{.example}
236236+ ## `lib.fileset.trace` usage example
237237+238238+ ```nix
239239+ trace (unions [ ./Makefile ./src ./tests/run.sh ]) null
240240+ =>
241241+ trace: /home/user/src/myProject
242242+ trace: - Makefile (regular)
243243+ trace: - src (all files in directory)
244244+ trace: - tests
245245+ trace: - run.sh (regular)
246246+ null
247247+ ```
248248+249249+ :::
250250+ */
251251+ trace = fileset:
218252 let
219253 # "fileset" would be a better name, but that would clash with the argument name,
220254 # and we cannot change that because of https://github.com/nix-community/nixdoc/issues/76
···224258 (_printFileset actualFileset)
225259 (x: x);
226260227227- /*
261261+ /**
228262 Incrementally evaluate and trace a file set in a pretty way.
229263 This function is only intended for debugging purposes.
230264 The exact tracing format is unspecified and may change.
···234268235269 This variant is useful for tracing file sets passed as arguments to other functions.
236270237237- Type:
238238- traceVal :: FileSet -> FileSet
271271+272272+ # Inputs
273273+274274+ `fileset`
275275+276276+ : The file set to trace and return.
277277+278278+ This argument can also be a path,
279279+ which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
280280+281281+ # Type
282282+283283+ ```
284284+ traceVal :: FileSet -> FileSet
285285+ ```
239286240240- Example:
241241- toSource {
242242- root = ./.;
243243- fileset = traceVal (unions [
244244- ./Makefile
245245- ./src
246246- ./tests/run.sh
247247- ]);
248248- }
249249- =>
250250- trace: /home/user/src/myProject
251251- trace: - Makefile (regular)
252252- trace: - src (all files in directory)
253253- trace: - tests
254254- trace: - run.sh (regular)
255255- "/nix/store/...-source"
287287+ # Examples
288288+ :::{.example}
289289+ ## `lib.fileset.traceVal` usage example
290290+291291+ ```nix
292292+ toSource {
293293+ root = ./.;
294294+ fileset = traceVal (unions [
295295+ ./Makefile
296296+ ./src
297297+ ./tests/run.sh
298298+ ]);
299299+ }
300300+ =>
301301+ trace: /home/user/src/myProject
302302+ trace: - Makefile (regular)
303303+ trace: - src (all files in directory)
304304+ trace: - tests
305305+ trace: - run.sh (regular)
306306+ "/nix/store/...-source"
307307+ ```
308308+309309+ :::
256310 */
257257- traceVal =
258258- /*
259259- The file set to trace and return.
260260-261261- This argument can also be a path,
262262- which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
263263- */
264264- fileset:
311311+ traceVal = fileset:
265312 let
266313 # "fileset" would be a better name, but that would clash with the argument name,
267314 # and we cannot change that because of https://github.com/nix-community/nixdoc/issues/76
···273320 # but that would then duplicate work for consumers of the fileset, because then they have to coerce it again
274321 actualFileset;
275322276276- /*
323323+ /**
277324 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`.
278325279326 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:
···286333287334 The name of the store path is always `source`.
288335289289- Type:
290290- toSource :: {
291291- root :: Path,
292292- fileset :: FileSet,
293293- } -> SourceLike
294294-295295- Example:
296296- # Import the current directory into the store
297297- # but only include files under ./src
298298- toSource {
299299- root = ./.;
300300- fileset = ./src;
301301- }
302302- => "/nix/store/...-source"
303303-304304- # Import the current directory into the store
305305- # but only include ./Makefile and all files under ./src
306306- toSource {
307307- root = ./.;
308308- fileset = union
309309- ./Makefile
310310- ./src;
311311- }
312312- => "/nix/store/...-source"
336336+ # Inputs
313337314314- # Trying to include a file outside the root will fail
315315- toSource {
316316- root = ./.;
317317- fileset = unions [
318318- ./Makefile
319319- ./src
320320- ../LICENSE
321321- ];
322322- }
323323- => <error>
338338+ Takes an attribute set with the following attributes
324339325325- # The root needs to point to a directory that contains all the files
326326- toSource {
327327- root = ../.;
328328- fileset = unions [
329329- ./Makefile
330330- ./src
331331- ../LICENSE
332332- ];
333333- }
334334- => "/nix/store/...-source"
340340+ `root` (Path; _required_)
335341336336- # The root has to be a local filesystem path
337337- toSource {
338338- root = "/nix/store/...-source";
339339- fileset = ./.;
340340- }
341341- => <error>
342342- */
343343- toSource = {
344344- /*
345345- (required) The local directory [path](https://nixos.org/manual/nix/stable/language/values.html#type-path) that will correspond to the root of the resulting store path.
342342+ : The local directory [path](https://nixos.org/manual/nix/stable/language/values.html#type-path) that will correspond to the root of the resulting store path.
346343 Paths in [strings](https://nixos.org/manual/nix/stable/language/values.html#type-string), including Nix store paths, cannot be passed as `root`.
347344 `root` has to be a directory.
348345···350347 Changing `root` only affects the directory structure of the resulting store path, it does not change which files are added to the store.
351348 The only way to change which files get added to the store is by changing the `fileset` attribute.
352349 :::
353353- */
354354- root,
355355- /*
356356- (required) The file set whose files to import into the store.
350350+351351+ `fileset` (FileSet; _required_)
352352+353353+ : The file set whose files to import into the store.
357354 File sets can be created using other functions in this library.
358355 This argument can also be a path,
359356 which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
···362359 If a directory does not recursively contain any file, it is omitted from the store path contents.
363360 :::
364361365365- */
362362+ # Type
363363+364364+ ```
365365+ toSource :: {
366366+ root :: Path,
367367+ fileset :: FileSet,
368368+ } -> SourceLike
369369+ ```
370370+371371+ # Examples
372372+ :::{.example}
373373+ ## `lib.fileset.toSource` usage example
374374+375375+ ```nix
376376+ # Import the current directory into the store
377377+ # but only include files under ./src
378378+ toSource {
379379+ root = ./.;
380380+ fileset = ./src;
381381+ }
382382+ => "/nix/store/...-source"
383383+384384+ # Import the current directory into the store
385385+ # but only include ./Makefile and all files under ./src
386386+ toSource {
387387+ root = ./.;
388388+ fileset = union
389389+ ./Makefile
390390+ ./src;
391391+ }
392392+ => "/nix/store/...-source"
393393+394394+ # Trying to include a file outside the root will fail
395395+ toSource {
396396+ root = ./.;
397397+ fileset = unions [
398398+ ./Makefile
399399+ ./src
400400+ ../LICENSE
401401+ ];
402402+ }
403403+ => <error>
404404+405405+ # The root needs to point to a directory that contains all the files
406406+ toSource {
407407+ root = ../.;
408408+ fileset = unions [
409409+ ./Makefile
410410+ ./src
411411+ ../LICENSE
412412+ ];
413413+ }
414414+ => "/nix/store/...-source"
415415+416416+ # The root has to be a local filesystem path
417417+ toSource {
418418+ root = "/nix/store/...-source";
419419+ fileset = ./.;
420420+ }
421421+ => <error>
422422+ ```
423423+424424+ :::
425425+ */
426426+ toSource = {
427427+ root,
366428 fileset,
367429 }:
368430 let
···418480 };
419481420482421421- /*
483483+ /**
422484 The list of file paths contained in the given file set.
423485424486 :::{.note}
···432494433495 The resulting list of files can be turned back into a file set using [`lib.fileset.unions`](#function-library-lib.fileset.unions).
434496435435- Type:
436436- toList :: FileSet -> [ Path ]
497497+498498+ # Inputs
499499+500500+ `fileset`
501501+502502+ : The file set whose file paths to return. This argument can also be a path, which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
503503+504504+ # Type
505505+506506+ ```
507507+ toList :: FileSet -> [ Path ]
508508+ ```
509509+510510+ # Examples
511511+ :::{.example}
512512+ ## `lib.fileset.toList` usage example
513513+514514+ ```nix
515515+ toList ./.
516516+ [ ./README.md ./Makefile ./src/main.c ./src/main.h ]
437517438438- Example:
439439- toList ./.
440440- [ ./README.md ./Makefile ./src/main.c ./src/main.h ]
518518+ toList (difference ./. ./src)
519519+ [ ./README.md ./Makefile ]
520520+ ```
441521442442- toList (difference ./. ./src)
443443- [ ./README.md ./Makefile ]
522522+ :::
444523 */
445445- toList =
446446- # The file set whose file paths to return.
447447- # This argument can also be a path,
448448- # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
449449- fileset:
524524+ toList = fileset:
450525 _toList (_coerce "lib.fileset.toList: Argument" fileset);
451526452452- /*
527527+ /**
453528 The file set containing all files that are in either of two given file sets.
454529 This is the same as [`unions`](#function-library-lib.fileset.unions),
455530 but takes just two file sets instead of a list.
···458533 The given file sets are evaluated as lazily as possible,
459534 with the first argument being evaluated first if needed.
460535461461- Type:
462462- union :: FileSet -> FileSet -> FileSet
536536+537537+ # Inputs
538538+539539+ `fileset1`
540540+541541+ : The first file set. This argument can also be a path, which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
542542+543543+ `fileset2`
544544+545545+ : The second file set. This argument can also be a path, which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
546546+547547+ # Type
548548+549549+ ```
550550+ union :: FileSet -> FileSet -> FileSet
551551+ ```
463552464464- Example:
465465- # Create a file set containing the file `Makefile`
466466- # and all files recursively in the `src` directory
467467- union ./Makefile ./src
553553+ # Examples
554554+ :::{.example}
555555+ ## `lib.fileset.union` usage example
556556+557557+ ```nix
558558+ # Create a file set containing the file `Makefile`
559559+ # and all files recursively in the `src` directory
560560+ union ./Makefile ./src
561561+562562+ # Create a file set containing the file `Makefile`
563563+ # and the LICENSE file from the parent directory
564564+ union ./Makefile ../LICENSE
565565+ ```
468566469469- # Create a file set containing the file `Makefile`
470470- # and the LICENSE file from the parent directory
471471- union ./Makefile ../LICENSE
567567+ :::
472568 */
473569 union =
474474- # The first file set.
475475- # This argument can also be a path,
476476- # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
477570 fileset1:
478478- # The second file set.
479479- # This argument can also be a path,
480480- # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
481571 fileset2:
482572 _unionMany
483573 (_coerceMany "lib.fileset.union" [
···491581 }
492582 ]);
493583494494- /*
584584+ /**
495585 The file set containing all files that are in any of the given file sets.
496586 This is the same as [`union`](#function-library-lib.fileset.unions),
497587 but takes a list of file sets instead of just two.
···500590 The given file sets are evaluated as lazily as possible,
501591 with earlier elements being evaluated first if needed.
502592503503- Type:
504504- unions :: [ FileSet ] -> FileSet
505593506506- Example:
507507- # Create a file set containing selected files
508508- unions [
509509- # Include the single file `Makefile` in the current directory
510510- # This errors if the file doesn't exist
511511- ./Makefile
594594+ # Inputs
512595513513- # Recursively include all files in the `src/code` directory
514514- # If this directory is empty this has no effect
515515- ./src/code
596596+ `filesets`
597597+598598+ : A list of file sets. The elements can also be paths, which get [implicitly coerced to file sets](#sec-fileset-path-coercion).
599599+600600+ # Type
516601517517- # Include the files `run.sh` and `unit.c` from the `tests` directory
518518- ./tests/run.sh
519519- ./tests/unit.c
602602+ ```
603603+ unions :: [ FileSet ] -> FileSet
604604+ ```
520605521521- # Include the `LICENSE` file from the parent directory
522522- ../LICENSE
523523- ]
606606+ # Examples
607607+ :::{.example}
608608+ ## `lib.fileset.unions` usage example
609609+610610+ ```nix
611611+ # Create a file set containing selected files
612612+ unions [
613613+ # Include the single file `Makefile` in the current directory
614614+ # This errors if the file doesn't exist
615615+ ./Makefile
616616+617617+ # Recursively include all files in the `src/code` directory
618618+ # If this directory is empty this has no effect
619619+ ./src/code
620620+621621+ # Include the files `run.sh` and `unit.c` from the `tests` directory
622622+ ./tests/run.sh
623623+ ./tests/unit.c
624624+625625+ # Include the `LICENSE` file from the parent directory
626626+ ../LICENSE
627627+ ]
628628+ ```
629629+630630+ :::
524631 */
525632 unions =
526526- # A list of file sets.
527527- # The elements can also be paths,
528528- # which get [implicitly coerced to file sets](#sec-fileset-path-coercion).
529633 filesets:
530634 if ! isList filesets then
531635 throw ''
···541645 _unionMany
542646 ];
543647544544- /*
648648+ /**
545649 The file set containing all files that are in both of two given file sets.
546650 See also [Intersection (set theory)](https://en.wikipedia.org/wiki/Intersection_(set_theory)).
547651548652 The given file sets are evaluated as lazily as possible,
549653 with the first argument being evaluated first if needed.
550654551551- Type:
552552- intersection :: FileSet -> FileSet -> FileSet
655655+656656+ # Inputs
657657+658658+ `fileset1`
659659+660660+ : The first file set. This argument can also be a path, which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
661661+662662+ `fileset2`
663663+664664+ : The second file set. This argument can also be a path, which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
665665+666666+ # Type
667667+668668+ ```
669669+ intersection :: FileSet -> FileSet -> FileSet
670670+ ```
671671+672672+ # Examples
673673+ :::{.example}
674674+ ## `lib.fileset.intersection` usage example
553675554554- Example:
555555- # Limit the selected files to the ones in ./., so only ./src and ./Makefile
556556- intersection ./. (unions [ ../LICENSE ./src ./Makefile ])
676676+ ```nix
677677+ # Limit the selected files to the ones in ./., so only ./src and ./Makefile
678678+ intersection ./. (unions [ ../LICENSE ./src ./Makefile ])
679679+ ```
680680+681681+ :::
557682 */
558683 intersection =
559559- # The first file set.
560560- # This argument can also be a path,
561561- # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
562684 fileset1:
563563- # The second file set.
564564- # This argument can also be a path,
565565- # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
566685 fileset2:
567686 let
568687 filesets = _coerceMany "lib.fileset.intersection" [
···580699 (elemAt filesets 0)
581700 (elemAt filesets 1);
582701583583- /*
702702+ /**
584703 The file set containing all files from the first file set that are not in the second file set.
585704 See also [Difference (set theory)](https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement).
586705587706 The given file sets are evaluated as lazily as possible,
588707 with the first argument being evaluated first if needed.
589708590590- Type:
591591- union :: FileSet -> FileSet -> FileSet
709709+710710+ # Inputs
711711+712712+ `positive`
713713+714714+ : The positive file set. The result can only contain files that are also in this file set. This argument can also be a path, which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
715715+716716+ `negative`
717717+718718+ : The negative file set. The result will never contain files that are also in this file set. This argument can also be a path, which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
719719+720720+ # Type
721721+722722+ ```
723723+ union :: FileSet -> FileSet -> FileSet
724724+ ```
725725+726726+ # Examples
727727+ :::{.example}
728728+ ## `lib.fileset.difference` usage example
729729+730730+ ```nix
731731+ # Create a file set containing all files from the current directory,
732732+ # except ones under ./tests
733733+ difference ./. ./tests
592734593593- Example:
594594- # Create a file set containing all files from the current directory,
595595- # except ones under ./tests
596596- difference ./. ./tests
735735+ let
736736+ # A set of Nix-related files
737737+ nixFiles = unions [ ./default.nix ./nix ./tests/default.nix ];
738738+ in
739739+ # Create a file set containing all files under ./tests, except ones in `nixFiles`,
740740+ # meaning only without ./tests/default.nix
741741+ difference ./tests nixFiles
742742+ ```
597743598598- let
599599- # A set of Nix-related files
600600- nixFiles = unions [ ./default.nix ./nix ./tests/default.nix ];
601601- in
602602- # Create a file set containing all files under ./tests, except ones in `nixFiles`,
603603- # meaning only without ./tests/default.nix
604604- difference ./tests nixFiles
744744+ :::
605745 */
606746 difference =
607607- # The positive file set.
608608- # The result can only contain files that are also in this file set.
609609- #
610610- # This argument can also be a path,
611611- # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
612747 positive:
613613- # The negative file set.
614614- # The result will never contain files that are also in this file set.
615615- #
616616- # This argument can also be a path,
617617- # which gets [implicitly coerced to a file set](#sec-fileset-path-coercion).
618748 negative:
619749 let
620750 filesets = _coerceMany "lib.fileset.difference" [
···632762 (elemAt filesets 0)
633763 (elemAt filesets 1);
634764635635- /*
765765+ /**
636766 Filter a file set to only contain files matching some predicate.
637767638638- Type:
639639- fileFilter ::
640640- ({
641641- name :: String,
642642- type :: String,
643643- hasExt :: String -> Bool,
644644- ...
645645- } -> Bool)
646646- -> Path
647647- -> FileSet
648768649649- Example:
650650- # Include all regular `default.nix` files in the current directory
651651- fileFilter (file: file.name == "default.nix") ./.
769769+ # Inputs
652770653653- # Include all non-Nix files from the current directory
654654- fileFilter (file: ! file.hasExt "nix") ./.
655655-656656- # Include all files that start with a "." in the current directory
657657- fileFilter (file: hasPrefix "." file.name) ./.
771771+ `predicate`
658772659659- # Include all regular files (not symlinks or others) in the current directory
660660- fileFilter (file: file.type == "regular") ./.
661661- */
662662- fileFilter =
663663- /*
664664- The predicate function to call on all files contained in given file set.
773773+ : The predicate function to call on all files contained in given file set.
665774 A file is included in the resulting file set if this function returns true for it.
666775667776 This function is called with an attribute set containing these attributes:
···678787 `hasExt "gitignore"` is true.
679788680789 Other attributes may be added in the future.
681681- */
790790+791791+ `path`
792792+793793+ : The path whose files to filter
794794+795795+ # Type
796796+797797+ ```
798798+ fileFilter ::
799799+ ({
800800+ name :: String,
801801+ type :: String,
802802+ hasExt :: String -> Bool,
803803+ ...
804804+ } -> Bool)
805805+ -> Path
806806+ -> FileSet
807807+ ```
808808+809809+ # Examples
810810+ :::{.example}
811811+ ## `lib.fileset.fileFilter` usage example
812812+813813+ ```nix
814814+ # Include all regular `default.nix` files in the current directory
815815+ fileFilter (file: file.name == "default.nix") ./.
816816+817817+ # Include all non-Nix files from the current directory
818818+ fileFilter (file: ! file.hasExt "nix") ./.
819819+820820+ # Include all files that start with a "." in the current directory
821821+ fileFilter (file: hasPrefix "." file.name) ./.
822822+823823+ # Include all regular files (not symlinks or others) in the current directory
824824+ fileFilter (file: file.type == "regular") ./.
825825+ ```
826826+827827+ :::
828828+ */
829829+ fileFilter =
682830 predicate:
683683- # The path whose files to filter
684831 path:
685832 if ! isFunction predicate then
686833 throw ''
···699846 else
700847 _fileFilter predicate path;
701848702702- /*
703703- Create a file set with the same files as a `lib.sources`-based value.
704704- This does not import any of the files into the store.
849849+ /**
850850+ Create a file set with the same files as a `lib.sources`-based value.
851851+ This does not import any of the files into the store.
852852+853853+ This can be used to gradually migrate from `lib.sources`-based filtering to `lib.fileset`.
854854+855855+ A file set can be turned back into a source using [`toSource`](#function-library-lib.fileset.toSource).
856856+857857+ :::{.note}
858858+ File sets cannot represent empty directories.
859859+ Turning the result of this function back into a source using `toSource` will therefore not preserve empty directories.
860860+ :::
705861706706- This can be used to gradually migrate from `lib.sources`-based filtering to `lib.fileset`.
707862708708- A file set can be turned back into a source using [`toSource`](#function-library-lib.fileset.toSource).
863863+ # Inputs
709864710710- :::{.note}
711711- File sets cannot represent empty directories.
712712- Turning the result of this function back into a source using `toSource` will therefore not preserve empty directories.
713713- :::
865865+ `source`
714866715715- Type:
867867+ : 1\. Function argument
868868+869869+ # Type
870870+871871+ ```
716872 fromSource :: SourceLike -> FileSet
873873+ ```
717874718718- Example:
875875+ # Examples
876876+ :::{.example}
877877+ ## `lib.fileset.fromSource` usage example
878878+879879+ ```nix
719880 # There's no cleanSource-like function for file sets yet,
720881 # but we can just convert cleanSource to a file set and use it that way
721882 toSource {
···740901 ./Makefile
741902 ./src
742903 ]);
904904+ ```
905905+906906+ :::
743907 */
744908 fromSource = source:
745909 let
···768932 # If there's no filter, no need to run the expensive conversion, all subpaths will be included
769933 _singleton path;
770934771771- /*
935935+ /**
772936 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.
773937774938 This function behaves like [`gitTrackedWith { }`](#function-library-lib.fileset.gitTrackedWith) - using the defaults.
775939776776- Type:
777777- gitTracked :: Path -> FileSet
940940+941941+ # Inputs
942942+943943+ `path`
778944779779- Example:
780780- # Include all files tracked by the Git repository in the current directory
781781- gitTracked ./.
945945+ : The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to the working directory of a local Git repository.
946946+ This directory must contain a `.git` file or subdirectory.
782947783783- # Include only files tracked by the Git repository in the parent directory
784784- # that are also in the current directory
785785- intersection ./. (gitTracked ../.)
948948+ # Type
949949+950950+ ```
951951+ gitTracked :: Path -> FileSet
952952+ ```
953953+954954+ # Examples
955955+ :::{.example}
956956+ ## `lib.fileset.gitTracked` usage example
957957+958958+ ```nix
959959+ # Include all files tracked by the Git repository in the current directory
960960+ gitTracked ./.
961961+962962+ # Include only files tracked by the Git repository in the parent directory
963963+ # that are also in the current directory
964964+ intersection ./. (gitTracked ../.)
965965+ ```
966966+967967+ :::
786968 */
787969 gitTracked =
788788- /*
789789- The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to the working directory of a local Git repository.
790790- This directory must contain a `.git` file or subdirectory.
791791- */
792970 path:
793971 _fromFetchGit
794972 "gitTracked"
···796974 path
797975 {};
798976799799- /*
977977+ /**
800978 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.
801979 The first argument allows configuration with an attribute set,
802980 while the second argument is the path to the Git working tree.
···820998 This may change in the future.
821999 :::
8221000823823- Type:
824824- gitTrackedWith :: { recurseSubmodules :: Bool ? false } -> Path -> FileSet
10011001+10021002+ # Inputs
10031003+10041004+ `options` (attribute set)
10051005+ : `recurseSubmodules` (optional, default: `false`)
10061006+ : Whether to recurse into [Git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to also include their tracked files.
10071007+ If `true`, this is equivalent to passing the [--recurse-submodules](https://git-scm.com/docs/git-ls-files#Documentation/git-ls-files.txt---recurse-submodules) flag to `git ls-files`.
10081008+10091009+ `path`
10101010+ : The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to the working directory of a local Git repository.
10111011+ This directory must contain a `.git` file or subdirectory.
10121012+10131013+ # Type
10141014+10151015+ ```
10161016+ gitTrackedWith :: { recurseSubmodules :: Bool ? false } -> Path -> FileSet
10171017+ ```
10181018+10191019+ # Examples
10201020+ :::{.example}
10211021+ ## `lib.fileset.gitTrackedWith` usage example
8251022826826- Example:
827827- # Include all files tracked by the Git repository in the current directory
828828- # and any submodules under it
829829- gitTracked { recurseSubmodules = true; } ./.
10231023+ ```nix
10241024+ # Include all files tracked by the Git repository in the current directory
10251025+ # and any submodules under it
10261026+ gitTracked { recurseSubmodules = true; } ./.
10271027+ ```
10281028+10291029+ :::
8301030 */
8311031 gitTrackedWith =
8321032 {
833833- /*
834834- (optional, default: `false`) Whether to recurse into [Git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to also include their tracked files.
835835-836836- If `true`, this is equivalent to passing the [--recurse-submodules](https://git-scm.com/docs/git-ls-files#Documentation/git-ls-files.txt---recurse-submodules) flag to `git ls-files`.
837837- */
8381033 recurseSubmodules ? false,
8391034 }:
840840- /*
841841- The [path](https://nixos.org/manual/nix/stable/language/values#type-path) to the working directory of a local Git repository.
842842- This directory must contain a `.git` file or subdirectory.
843843- */
8441035 path:
8451036 if ! isBool recurseSubmodules then
8461037 throw "lib.fileset.gitTrackedWith: Expected the attribute `recurseSubmodules` of the first argument to be a boolean, but it's a ${typeOf recurseSubmodules} instead."