You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*input* must be an attribute set with the following attributes:
246
-
247
-
- `type` (String, required)
248
-
249
-
One of the [supported source types](#source-types).
250
-
This determines other required and allowed input attributes.
251
-
252
-
- `narHash` (String, optional)
253
-
254
-
The `narHash` parameter can be used to substitute the source of the tree.
255
-
It also allows for verification of tree contents that may not be provided by the underlying transfer mechanism.
256
-
If `narHash` is set, the source is first looked up is the Nix store and [substituters](@docroot@/command-ref/conf-file.md#conf-substituters), and only fetched if not available.
257
-
258
-
A subset of the output attributes of `fetchTree` can be re-used for subsequent calls to `fetchTree` to produce the same result again.
259
-
That is, `fetchTree` is idempotent.
260
-
261
-
Downloads are cached in `$XDG_CACHE_HOME/nix`.
262
-
The remote source is fetched from the network if both are true:
263
-
- A NAR hash is supplied and the corresponding store path is not [valid](@docroot@/glossary.md#gloss-validity), that is, not available in the store
264
-
265
-
> **Note**
266
-
>
267
-
> [Substituters](@docroot@/command-ref/conf-file.md#conf-substituters) are not used in fetching.
268
-
269
-
- There is no cache entry or the cache entry is older than [`tarball-ttl`](@docroot@/command-ref/conf-file.md#conf-tarball-ttl)
270
-
271
-
## Source types
272
-
273
-
The following source types and associated input attributes are supported.
274
-
275
-
<!-- TODO: It would be soooo much more predictable to work with (and
276
-
document) if `fetchTree` was a curried call with the first parameter for
277
-
`type` or an attribute like `builtins.fetchTree.git`! -->
238
+
.doc = []() -> std::string {
239
+
std::string doc = stripIndentation(R"(
240
+
Fetch a file system tree or a plain file using one of the supported backends and return an attribute set with:
278
241
279
-
- `"file"`
242
+
- the resulting fixed-output [store path](@docroot@/store/store-path.md)
243
+
- the corresponding [NAR](@docroot@/store/file-system-object/content-address.md#serial-nix-archive) hash
This is similar to [`builtins.fetchurl`](@docroot@/language/builtins.md#builtins-fetchurl)
246
+
*input* must be an attribute set with the following attributes:
283
247
284
-
- `url` (String, required)
248
+
- `type` (String, required)
285
249
286
-
Supported protocols:
250
+
One of the [supported source types](#source-types).
251
+
This determines other required and allowed input attributes.
287
252
288
-
- `https`
253
+
- `narHash` (String, optional)
289
254
290
-
> **Example**
291
-
>
292
-
> ```nix
293
-
> fetchTree {
294
-
> type = "file";
295
-
> url = "https://example.com/index.html";
296
-
> }
297
-
> ```
255
+
The `narHash` parameter can be used to substitute the source of the tree.
256
+
It also allows for verification of tree contents that may not be provided by the underlying transfer mechanism.
257
+
If `narHash` is set, the source is first looked up is the Nix store and [substituters](@docroot@/command-ref/conf-file.md#conf-substituters), and only fetched if not available.
298
258
299
-
- `http`
259
+
A subset of the output attributes of `fetchTree` can be re-used for subsequent calls to `fetchTree` to produce the same result again.
260
+
That is, `fetchTree` is idempotent.
300
261
301
-
Insecure HTTP transfer for legacy sources.
262
+
Downloads are cached in `$XDG_CACHE_HOME/nix`.
263
+
The remote source is fetched from the network if both are true:
264
+
- A NAR hash is supplied and the corresponding store path is not [valid](@docroot@/glossary.md#gloss-validity), that is, not available in the store
302
265
303
-
> **Warning**
266
+
> **Note**
304
267
>
305
-
> HTTP performs no encryption or authentication.
306
-
> Use a `narHash` known in advance to ensure the output has expected contents.
307
-
308
-
- `file`
309
-
310
-
A file on the local file system.
311
-
312
-
> **Example**
313
-
>
314
-
> ```nix
315
-
> fetchTree {
316
-
> type = "file";
317
-
> url = "file:///home/eelco/nix/README.md";
318
-
> }
319
-
> ```
320
-
321
-
- `"git"`
322
-
323
-
Fetch a Git tree and copy it to the Nix store.
324
-
This is similar to [`builtins.fetchGit`](@docroot@/language/builtins.md#builtins-fetchGit).
325
-
326
-
- `allRefs` (Bool, optional)
327
-
328
-
By default, this has no effect. This becomes relevant only once `shallow` cloning is disabled.
329
-
330
-
Whether to fetch all references (eg. branches and tags) of the repository.
331
-
With this argument being true, it's possible to load a `rev` from *any* `ref`.
332
-
(Without setting this option, only `rev`s from the specified `ref` are supported).
333
-
334
-
Default: `false`
335
-
336
-
- `lastModified` (Integer, optional)
337
-
338
-
Unix timestamp of the fetched commit.
339
-
340
-
If set, pass through the value to the output attribute set.
341
-
Otherwise, generated from the fetched Git tree.
268
+
> [Substituters](@docroot@/command-ref/conf-file.md#conf-substituters) are not used in fetching.
342
269
343
-
- `lfs` (Bool, optional)
270
+
- There is no cache entry or the cache entry is older than [`tarball-ttl`](@docroot@/command-ref/conf-file.md#conf-tarball-ttl)
344
271
345
-
Fetch any [Git LFS](https://git-lfs.com/) files.
272
+
## Source types
346
273
347
-
Default: `false`
274
+
The following source types and associated input attributes are supported.
348
275
349
-
- `ref` (String, optional)
276
+
<!-- TODO: It would be soooo much more predictable to work with (and
277
+
document) if `fetchTree` was a curried call with the first parameter for
278
+
`type` or an attribute like `builtins.fetchTree.git`! -->
279
+
)");
350
280
351
-
By default, this has no effect. This becomes relevant only once `shallow` cloning is disabled.
352
-
353
-
A [Git reference](https://git-scm.com/book/en/v2/Git-Internals-Git-References), such as a branch or tag name.
354
-
355
-
Default: `"HEAD"`
356
-
357
-
- `rev` (String, optional)
358
-
359
-
A Git revision; a commit hash.
360
-
361
-
Default: the tip of `ref`
362
-
363
-
- `revCount` (Integer, optional)
364
-
365
-
Number of revisions in the history of the Git repository before the fetched commit.
366
-
367
-
If set, pass through the value to the output attribute set.
368
-
Otherwise, generated from the fetched Git tree.
369
-
370
-
- `shallow` (Bool, optional)
371
-
372
-
Make a shallow clone when fetching the Git tree.
373
-
When this is enabled, the options `ref` and `allRefs` have no effect anymore.
The following input types are still subject to change:
382
312
383
-
- `url` (String, required)
313
+
- `"path"`
314
+
- `"github"`
315
+
- `"gitlab"`
316
+
- `"sourcehut"`
317
+
- `"mercurial"`
384
318
385
-
The URL formats supported are the same as for Git itself.
319
+
*input* can also be a [URL-like reference](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references).
320
+
The additional input types and the URL-like syntax requires the [`flakes` experimental feature](@docroot@/development/experimental-features.md#xp-feature-flakes) to be enabled.
386
321
387
322
> **Example**
388
323
>
324
+
> Fetch a GitHub repository using the attribute set representation:
> If the URL points to a local directory, and no `ref` or `rev` is given, Nix only considers files added to the Git index, as listed by `git ls-files` but use the *current file contents* of the Git working directory.
399
-
400
-
- `"tarball"`
401
-
402
-
Download a tar archive and extract it into the Nix store.
403
-
This has the same underlying implementation as [`builtins.fetchTarball`](@docroot@/language/builtins.md#builtins-fetchTarball)
The following input types are still subject to change:
417
-
418
-
- `"path"`
419
-
- `"github"`
420
-
- `"gitlab"`
421
-
- `"sourcehut"`
422
-
- `"mercurial"`
423
-
424
-
*input* can also be a [URL-like reference](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references).
425
-
The additional input types and the URL-like syntax requires the [`flakes` experimental feature](@docroot@/development/experimental-features.md#xp-feature-flakes) to be enabled.
426
-
427
-
> **Example**
428
-
>
429
-
> Fetch a GitHub repository using the attribute set representation:
0 commit comments