-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fetchTree: add documentation #5556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| **Warning**: | ||
| This section is **experimental** and its interface is subject to change. | ||
|
|
||
| # Fetchers | ||
|
|
||
| Nix supports fetching source trees | ||
| from different locations | ||
| through the `fetchTree` builtin. | ||
|
|
||
| Below we document the supported backends | ||
| and their configuration options. | ||
|
|
||
| ## Git | ||
|
|
||
| Allows you to fetch a Git source tree (similar to a `git clone`). | ||
|
|
||
| > **Note** | ||
| > | ||
| > The `.git/` folder won't be saved for reproducibility. | ||
|
|
||
| Options: | ||
|
|
||
| - `type` | ||
|
|
||
| Must be equal to `"git"`. | ||
| - `url` | ||
|
|
||
| Location of the git repository as accepted by `git` | ||
| (i.e. a local path, http(s) or SSH URL). | ||
| - `ref` | ||
|
|
||
| The git ref to look for the requested revision under. | ||
| This is often a branch or tag name. | ||
| Defaults to `HEAD`. | ||
|
|
||
| If `ref` does not start with `refs/`, it will be prefixed with `refs/heads/`. | ||
| - `rev` | ||
|
|
||
| The git revision to fetch. Defaults to the tip of `ref`. | ||
| - `submodules` | ||
|
|
||
| A Boolean parameter that specifies | ||
| whether submodules should be checked out. | ||
| Defaults to `false`. | ||
| - `shallow` | ||
|
|
||
| If `true` only the HEAD commit will be fetched. | ||
| Defaults to `true`. | ||
| - `allRefs` | ||
|
|
||
| Whether to fetch all refs of the repository. | ||
|
|
||
| With this argument being true, | ||
| it's possible to load a `rev` from *any* `ref` | ||
| (by default only `rev`s from the specified `ref` are supported). | ||
| Defaults to `false`. | ||
|
|
||
|
|
||
| Examples: | ||
|
|
||
| - To fetch a private repository over SSH: | ||
|
|
||
| ```nix | ||
| builtins.fetchTree { | ||
| type = "git"; | ||
| url = "git@github.com:my-secret/repo.git"; | ||
| ref = "main"; | ||
| rev = "2aeb84a3aac9bba4f9b7aa8731d35f3d6925b40f"; | ||
| } | ||
| ``` | ||
|
|
||
| - To fetch an arbitrary reference: | ||
|
|
||
| ```nix | ||
| builtins.fetchTree { | ||
| type = "git"; | ||
| url = "https://github.com/NixOS/nix.git"; | ||
| ref = "refs/heads/0.5-release"; | ||
| } | ||
| ``` | ||
|
|
||
| - If the revision you're looking for is in the default branch of | ||
| the git repository you don't strictly need to specify the branch | ||
| name in the `ref` attribute. | ||
|
|
||
| However, if the revision you're looking for is in a future | ||
| branch for the non-default branch you will need to specify the | ||
| the `ref` attribute as well. | ||
|
|
||
| ```nix | ||
| builtins.fetchTree { | ||
| type = "git"; | ||
| url = "https://github.com/nixos/nix.git"; | ||
| rev = "841fcbd04755c7a2865c51c1e2d3b045976b7452"; | ||
| ref = "1.11-maintenance"; | ||
| } | ||
| ``` | ||
|
|
||
| > **Note** | ||
| > | ||
| > It is nice to always specify the branch which a revision | ||
| > belongs to. Without the branch being specified, the fetcher | ||
| > might fail if the default branch changes. Additionally, it can | ||
| > be confusing to try a commit from a non-default branch and see | ||
| > the fetch fail. If the branch is specified the fault is much | ||
| > more obvious. | ||
|
|
||
| - If the revision you're looking for is in the default branch of | ||
| the git repository you may omit the `ref` attribute. | ||
|
|
||
| ```nix | ||
| builtins.fetchTree { | ||
| type = "git"; | ||
| url = "https://github.com/nixos/nix.git"; | ||
| rev = "841fcbd04755c7a2865c51c1e2d3b045976b7452"; | ||
| } | ||
| ``` | ||
|
|
||
| - To fetch a specific tag: | ||
|
|
||
| ```nix | ||
| builtins.fetchTree { | ||
| type = "git"; | ||
| url = "https://github.com/nixos/nix.git"; | ||
| ref = "refs/tags/1.9"; | ||
| } | ||
| ``` | ||
|
|
||
| - To fetch the latest version of a remote branch: | ||
|
|
||
| ```nix | ||
| builtins.fetchTree { | ||
| type = "git"; | ||
| url = "ssh://git@github.com/nixos/nix.git"; | ||
| ref = "master"; | ||
| } | ||
| ``` | ||
|
|
||
| > **Note** | ||
| > | ||
| > Nix will refetch the branch in accordance with | ||
| > the option `tarball-ttl`. | ||
|
|
||
| > **Note** | ||
| > | ||
| > Fetching the latest version of a remote branch | ||
| > is disabled in *Pure evaluation mode*. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can this be experimental when all the old fetchers are now using this under the hood?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the warning because of this small detail:
nix/src/libexpr/primops/fetchTree.cc
Line 179 in bceda30
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think here’s a contradiction here: This is indeed used internally, but the interface isn’t stable yet. So it makes sense to mark this as experimental