···11+# pkgs.nix-gitignore {#sec-pkgs-nix-gitignore}
22+33+`pkgs.nix-gitignore` is a function that acts similarly to `builtins.filterSource` but also allows filtering with the help of the gitignore format.
44+55+## Usage {#sec-pkgs-nix-gitignore-usage}
66+77+`pkgs.nix-gitignore` exports a number of functions, but you\'ll most likely need either `gitignoreSource` or `gitignoreSourcePure`. As their first argument, they both accept either 1. a file with gitignore lines or 2. a string with gitignore lines, or 3. a list of either of the two. They will be concatenated into a single big string.
88+99+```nix
1010+{ pkgs ? import <nixpkgs> {} }:
1111+1212+ nix-gitignore.gitignoreSource [] ./source
1313+ # Simplest version
1414+1515+ nix-gitignore.gitignoreSource "supplemental-ignores\n" ./source
1616+ # This one reads the ./source/.gitignore and concats the auxiliary ignores
1717+1818+ nix-gitignore.gitignoreSourcePure "ignore-this\nignore-that\n" ./source
1919+ # Use this string as gitignore, don't read ./source/.gitignore.
2020+2121+ nix-gitignore.gitignoreSourcePure ["ignore-this\nignore-that\n", ~/.gitignore] ./source
2222+ # It also accepts a list (of strings and paths) that will be concatenated
2323+ # once the paths are turned to strings via readFile.
2424+```
2525+2626+These functions are derived from the `Filter` functions by setting the first filter argument to `(_: _: true)`:
2727+2828+```nix
2929+gitignoreSourcePure = gitignoreFilterSourcePure (_: _: true);
3030+gitignoreSource = gitignoreFilterSource (_: _: true);
3131+```
3232+3333+Those filter functions accept the same arguments the `builtins.filterSource` function would pass to its filters, thus `fn: gitignoreFilterSourcePure fn ""` should be extensionally equivalent to `filterSource`. The file is blacklisted if it\'s blacklisted by either your filter or the gitignoreFilter.
3434+3535+If you want to make your own filter from scratch, you may use
3636+3737+```nix
3838+gitignoreFilter = ign: root: filterPattern (gitignoreToPatterns ign) root;
3939+```
4040+4141+## gitignore files in subdirectories {#sec-pkgs-nix-gitignore-usage-recursive}
4242+4343+If you wish to use a filter that would search for .gitignore files in subdirectories, just like git does by default, use this function:
4444+4545+```nix
4646+gitignoreFilterRecursiveSource = filter: patterns: root:
4747+# OR
4848+gitignoreRecursiveSource = gitignoreFilterSourcePure (_: _: true);
4949+```
-70
doc/functions/nix-gitignore.xml
···11-<section xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xmlns:xi="http://www.w3.org/2001/XInclude"
44- xml:id="sec-pkgs-nix-gitignore">
55- <title>pkgs.nix-gitignore</title>
66-77- <para>
88- <function>pkgs.nix-gitignore</function> is a function that acts similarly to <literal>builtins.filterSource</literal> but also allows filtering with the help of the gitignore format.
99- </para>
1010-1111- <section xml:id="sec-pkgs-nix-gitignore-usage">
1212- <title>Usage</title>
1313-1414- <para>
1515- <literal>pkgs.nix-gitignore</literal> exports a number of functions, but you'll most likely need either <literal>gitignoreSource</literal> or <literal>gitignoreSourcePure</literal>. As their first argument, they both accept either 1. a file with gitignore lines or 2. a string with gitignore lines, or 3. a list of either of the two. They will be concatenated into a single big string.
1616- </para>
1717-1818-<programlisting><![CDATA[
1919-{ pkgs ? import <nixpkgs> {} }:
2020-2121- nix-gitignore.gitignoreSource [] ./source
2222- # Simplest version
2323-2424- nix-gitignore.gitignoreSource "supplemental-ignores\n" ./source
2525- # This one reads the ./source/.gitignore and concats the auxiliary ignores
2626-2727- nix-gitignore.gitignoreSourcePure "ignore-this\nignore-that\n" ./source
2828- # Use this string as gitignore, don't read ./source/.gitignore.
2929-3030- nix-gitignore.gitignoreSourcePure ["ignore-this\nignore-that\n", ~/.gitignore] ./source
3131- # It also accepts a list (of strings and paths) that will be concatenated
3232- # once the paths are turned to strings via readFile.
3333- ]]></programlisting>
3434-3535- <para>
3636- These functions are derived from the <literal>Filter</literal> functions by setting the first filter argument to <literal>(_: _: true)</literal>:
3737- </para>
3838-3939-<programlisting><![CDATA[
4040-gitignoreSourcePure = gitignoreFilterSourcePure (_: _: true);
4141-gitignoreSource = gitignoreFilterSource (_: _: true);
4242- ]]></programlisting>
4343-4444- <para>
4545- Those filter functions accept the same arguments the <literal>builtins.filterSource</literal> function would pass to its filters, thus <literal>fn: gitignoreFilterSourcePure fn ""</literal> should be extensionally equivalent to <literal>filterSource</literal>. The file is blacklisted iff it's blacklisted by either your filter or the gitignoreFilter.
4646- </para>
4747-4848- <para>
4949- If you want to make your own filter from scratch, you may use
5050- </para>
5151-5252-<programlisting><![CDATA[
5353-gitignoreFilter = ign: root: filterPattern (gitignoreToPatterns ign) root;
5454- ]]></programlisting>
5555- </section>
5656-5757- <section xml:id="sec-pkgs-nix-gitignore-usage-recursive">
5858- <title>gitignore files in subdirectories</title>
5959-6060- <para>
6161- If you wish to use a filter that would search for .gitignore files in subdirectories, just like git does by default, use this function:
6262- </para>
6363-6464-<programlisting><![CDATA[
6565-gitignoreFilterRecursiveSource = filter: patterns: root:
6666-# OR
6767-gitignoreRecursiveSource = gitignoreFilterSourcePure (_: _: true);
6868- ]]></programlisting>
6969- </section>
7070-</section>